471,108 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,108 software developers and data experts.

Forms Dispose method triggering SelectedIndexChanged event on close

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


Jul 26 '07 #1
0 1833

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Joshua Russell | last post: by
6 posts views Thread by Ayende Rahien | last post: by
reply views Thread by Hector | last post: by
reply views Thread by Bruce | last post: by
12 posts views Thread by Capt_Ron | last post: by
11 posts views Thread by Nick | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.