how to cancel events for controls on a form when the form is closi

G

Guest

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?
 
J

Jesse Houwing

dchman said:
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
 
G

Guest

Thanks for the quick response. I'll give your suggestion a try tomorrow.
The control is actually a common control supplied with VS2005.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top