Problem with a handler firing after it's parent form has closed. How do I stop this?
Posted on 2008-11-02
Here's the summary of my problem:
My application opens a new form (of Class 'note') for each item in a database it loads at startup. In Public Class note the handlers for the control events are added at runtime (AddHandler). There is an event in Class note to remove the form, and its corresponding row in the dataset. Then the relevant form closes.
All this works fine but one of the control events defined in the Public Class note triggers as soons as the form closes. It is the Textbox.LostFocus event. The functions of this event throw an exception because, of course, the appropriate line in the database doesn't exist.
I can of course manually remove the handlers in the FormClosing event, but I'm curious as to why the handlers are still there. Is this something to do with the fact that they are defined at runtime?
Thanks in advance.