G
Guest
Guys,
I've written a custom control (or at least tweaked someone else's!) in C# to
be used on forms (rather than asp.net forms). The control is a date time
picker, but its Value property returns a special date time object we have
written, when a date is selected. The property object's class is called
OptionalDateTime. This is basically to allow blank dates, and is useful when
a date to be entered is not mandatory.
This is the problem: If I draw the control on a form, it works fine, and I
can read the Value property of my control using the Value property. However,
for some reason, it suddenly stops working at random!
I think the problem is to do with code created automatically in the
InitializeComponent() method. When the control is first drawn on the form,
this gets created:
this.lockableOptionalLightDateTimePicker1.Value =
((HCS.DataTypes.Time.OptionalDateTime)(resources.GetObject("lockableOptionalLightDateTimePicker1.Value")));
When it stops working, the code is the same as listed here, but I start
getting an error with this line of code. The problem is hard to recreate
reliably at the moment, but I am working on it. I’m pretty sure the error is
the “Object reference not set to an instance of an object†exception, but I
will confirm this.
Has anyone got any ideas? Is it bad practice to have a Value property that
returns an object type? I wouldn’t have thought so, since other Microsoft
controls do this; for instance, when colors are involved.
Your help in this matter would be greatly appreciated!
Thanks,
Steve.
I've written a custom control (or at least tweaked someone else's!) in C# to
be used on forms (rather than asp.net forms). The control is a date time
picker, but its Value property returns a special date time object we have
written, when a date is selected. The property object's class is called
OptionalDateTime. This is basically to allow blank dates, and is useful when
a date to be entered is not mandatory.
This is the problem: If I draw the control on a form, it works fine, and I
can read the Value property of my control using the Value property. However,
for some reason, it suddenly stops working at random!
I think the problem is to do with code created automatically in the
InitializeComponent() method. When the control is first drawn on the form,
this gets created:
this.lockableOptionalLightDateTimePicker1.Value =
((HCS.DataTypes.Time.OptionalDateTime)(resources.GetObject("lockableOptionalLightDateTimePicker1.Value")));
When it stops working, the code is the same as listed here, but I start
getting an error with this line of code. The problem is hard to recreate
reliably at the moment, but I am working on it. I’m pretty sure the error is
the “Object reference not set to an instance of an object†exception, but I
will confirm this.
Has anyone got any ideas? Is it bad practice to have a Value property that
returns an object type? I wouldn’t have thought so, since other Microsoft
controls do this; for instance, when colors are involved.
Your help in this matter would be greatly appreciated!
Thanks,
Steve.