By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,144 Members | 1,056 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,144 IT Pros & Developers. It's quick & easy.

Forms Dispose method triggering SelectedIndexChanged event on close

P: n/a

I'm a C# Newbie, so if I've missed the obvious here go easy!!!

I have a form opened from a MDI parent. The form has a data bound
combo box, with a SelectedIndexChanged event (fills a list view box on
the same form depending on selection). It all works fine except when
you close either the form itself or it's MDI parent. Somehow as the
form is closing this event is triggered, and crashes out with an un-
handled error (even though it's in a try catch block!!) when it gets
to the part where it has to read the combo box value, which now has
been disposed along with the control.

The error goes away completely when I comment out the auto-generated
components.Dispose(); part of the form's class. In my limited
knowledge, I guess this to be either one of two strange occurances:
1. The Dispose method is itself triggering the SelectedIndexChanged
event, or
2. The close event somehow triggers the SelectedIndexChanged event but
the dispose kills the control as it it running.

I'm not sure what is going on here - but would appreciate any input.
The event definition appears to be normal:

this.comboBox2.SelectedIndexChanged += new
System.EventHandler(this.comboBox2_SelectedIndexCh anged);

And there are no other references to the function elsewhere in the
forms class. I'm a little stumped at what's going on here! Any help
appreciated!

Bill

Jul 26 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.