There are a number of ways to get around this.
One way that I have done this in the past is to have a
private bool
variable on the form that I call something like
pauseEvents
.
Before you start to fill the
ComboBox
with values, you set
pauseEvents
to
true
. (or a more object-oriented way might be to have a function called
PauseEvents
that you call ie.
this.PauseEvents()
that sets the boolean value to
true
and then call another function called
ResumeEvents
.) Then, after you've finished filling it and setting the SelectedIndex to -1, set
pauseEvents
to
true
.
Then, in your
SelectedIndexChanged
event, the very first thing you have is an if statement...
if(pauseEvents)
return;
That will prevent anything else from running. IMO, there's nothing wrong with doing this.
You can also do as Vipin said. I generally do a combination of the two.