Can anyone tell me what's wrong in this part of code

Posted by Mobin on Stack Overflow See other posts from Stack Overflow or by Mobin
Published on 2010-05-14T13:42:37Z Indexed on 2010/05/14 16:04 UTC
Read the original article Hit count: 274

Filed under:
|
string name = ((DateTimePicker)sender).Name.ToString();
        name = name.Substring(0, name.Length - 1);
        name = name + "4";
        TimeSpan duration = new TimeSpan();
        duration = ((DateTimePicker)sender).Value - ((DateTimePicker)panel2.Controls[name]).Value;
        name = name.Substring(0, name.Length - 1);
        name = name + "6";
        ((MaskedTextBox)panel2.Controls[name]).Text = duration.ToString();

On execution it gives me Object reference not set to instance of an object similar functionality is used on other places but I can't find out what I have to reinitialize here :$

alt text

The casting for datetimepicker is fine I have to get a name for the datetiempicker to identify the row it's on in my form and the picker before that to calculate their differences and then print that difference in a maskedtext box from the control whose name I make using names of two datetimepickers but when I access controls in the error line I get this message.

© Stack Overflow or respective owner

Related posts about c#

Related posts about maskedtextbox