Stop comboBox's selectedIndexChanged event from firing when the form loads
Solution 1:
If you want to react only when the user change the selected item in the combo box, then it is better to subscribe to SelectionChangeCommitted.
Solution 2:
You can simply unbind the SelectedIndexChanged
event, call your fill
function and bind the SelectedIndexChanged
event again. Unfortunately, this doesn't work with a grid.
For example:
this.cmb.SelectionChanged -= new System.EventHandler(this.cmb_SelectionChanged);
cmb.fill(); //Your function
this.cmb.SelectionChanged += new System.EventHandler(this.cmb_SelectionChanged);
Solution 3:
Be sure to set the DataSource
property in your onload()
function after assigning the ValueMember
and Datamember
properties.
This will help you to solve your problem!
Solution 4:
Why not have a boolean
flag that indicates when your Form
has finished loading?
In your SelectionChanged
event, check if the boolean
flag is true
. If it is true
then handle the event, otherwise ignore it.