Reputation: 113
How do I prevent code from executing in the SelectedValueChange event of a combobox when the combobox is being loaded for the first time? I need the code to execute when the user has selected a new value.
Upvotes: 4
Views: 1941
Reputation: 3644
I prefer the SelectedIndexChanged event as its behaviour seems to better model that of the underlying Win32 API making it predictable.
Some of the more esoteric events offered by the controls simply do not model the behaviour that one would expect from their name.
Upvotes: 0
Reputation: 617
If you only want some code to be executed when the user changes the combobox you can subscribe to SelectionChangeCommitted instead of SelectionChanged. "SelectionChangeCommitted " doesn't get called when the combobox selection is changed programmatically.
Upvotes: 10
Reputation: 63126
You have a few options.
Rather than letting the designer hookup the event handler you can do it yourself after loading
You can set a flag in your application for "loading" and put code inside your SelectedValueChange event to check !loading before continuing.
Personally I would just add the handler after load if it is causing issues.
Upvotes: 3