Winforms ComboBox SelectedValueChange Event

How can I prevent code execution in the SelectedValueChange event when combobox is unloaded for the first time? I need code to execute when the user selects a new value.

+4
source share
3 answers

You have several options.

  • Instead of letting the designer attach an event handler, you can do it yourself after loading

  • You can set the flag in the application to “load” and place the code inside your SelectedValueChange event to check the load before continuing.

Personally, I would just add a handler after loading if it causes problems.

+3
source

If you want some code to be executed when the user changes the drop-down list, you can subscribe to SelectionChangeCommitted instead of SelectionChanged. "SelectionChangeCommitted" is not called when the combobox program selection changes programmatically.

+10
source

I prefer the SelectedIndexChanged event, as its behavior seems to better model the core Win32 API, which makes it predictable.

Some of the more esoteric events offered by the controls simply do not model the behavior that might be expected on their behalf.

0
source

All Articles