dchman wrote:
I have a C# app in VS2005. the form has a datetime picker with valuechanged
event. When the form closes, the valuechanged event is fired and an error is
thrown in its code when it tries to get a selected value from a combobox
which apparently doesn't exist anymore. I get around the problem with some
error handling, but what I really want to know, is there a way to cancel the
control event handlers on a form when the form is closing?
It seems like the DateTime picker isn't clearing it's events when it has
to. Is it a bought component, or was it written by yourself?
ValueChanged events should not happen when closing and when the form is
invisible.
If it was a bought/3rd party control, then you can always unsubscribe
the event yourself in the form's closing event. Though this is a
workaround it should do the tricks without adding extra error handling:
form_Closing(...)
{
datepicker.ValueChanged -= datePicker_ValueChanged;
}
Jesse Houwing