Skip to main content
[Edit removed during grace period]; edited tags
Link
user692942
  • 16.4k
  • 8
  • 85
  • 196
added tags, deleted irrelevant note about moving from HI to NC
Source Link

I wrote a method to handle a comboBox's SelectedIndexChanged event.

In the constructor I populated the comboBox, and this activated my event-handling method. Which I don't want since nobody clicked on the comboBox.

Is there an easy way to get the comboBox not to fire the event unless the user clicked it?

If that is not possible, is there a way to disconnect the event to the method temporarily? Could I just set "my_combo.SelectedIndexChanged = null" and then create a new System.EventHandler?

Or I guess I could create some kind of boolean member variable that I can switch on or off and put a branch check in my method. That seems like a kludge, though.

Also I just moved to North Carolina from Hawaii and NC is way, way better.

I wrote a method to handle a comboBox's SelectedIndexChanged event.

In the constructor I populated the comboBox, and this activated my event-handling method. Which I don't want since nobody clicked on the comboBox.

Is there an easy way to get the comboBox not to fire the event unless the user clicked it?

If that is not possible, is there a way to disconnect the event to the method temporarily? Could I just set "my_combo.SelectedIndexChanged = null" and then create a new System.EventHandler?

Or I guess I could create some kind of boolean member variable that I can switch on or off and put a branch check in my method. That seems like a kludge, though.

Also I just moved to North Carolina from Hawaii and NC is way, way better.

I wrote a method to handle a comboBox's SelectedIndexChanged event.

In the constructor I populated the comboBox, and this activated my event-handling method. Which I don't want since nobody clicked on the comboBox.

Is there an easy way to get the comboBox not to fire the event unless the user clicked it?

If that is not possible, is there a way to disconnect the event to the method temporarily? Could I just set "my_combo.SelectedIndexChanged = null" and then create a new System.EventHandler?

Or I guess I could create some kind of boolean member variable that I can switch on or off and put a branch check in my method. That seems like a kludge, though.

Source Link
micahhoover
  • 2.2k
  • 8
  • 35
  • 57

Fire comboBox SelectedIndexChanged only from user click

I wrote a method to handle a comboBox's SelectedIndexChanged event.

In the constructor I populated the comboBox, and this activated my event-handling method. Which I don't want since nobody clicked on the comboBox.

Is there an easy way to get the comboBox not to fire the event unless the user clicked it?

If that is not possible, is there a way to disconnect the event to the method temporarily? Could I just set "my_combo.SelectedIndexChanged = null" and then create a new System.EventHandler?

Or I guess I could create some kind of boolean member variable that I can switch on or off and put a branch check in my method. That seems like a kludge, though.

Also I just moved to North Carolina from Hawaii and NC is way, way better.