views:

82

answers:

3

I have a form with a ComboBox that provides a dropdownlist. On the comboBox's SelectedIndexChanged event, am running some code, but i don't want that code to run when the form loads. Unfortunately, when i load the form (before i make a selection in the combobox), SelectedIndexChanged of the combobox fires ( i think when the combobox is databinding). Is there a way of avoiding such behaviour?

+1  A: 

You can simply unbind fill bind SelectedIndexChanged event. Unfortunately it doesn't works with grid.

eg.

this.cmb.SelectionChanged -= new System.EventHandler(this.cmb_SelectionChanged);
cmb.fill()//your function
this.cmb.SelectionChanged += new System.EventHandler(this.cmb_SelectionChanged);
Shantanu Gupta
+2  A: 

If you want to react only when user change selected item in combo box, then it is better to subscribe to SelectionChangeCommitted.

arbiter
@arbiter: Nice solution, i will try it. seems to be better than my answer.
Shantanu Gupta
A: 

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.

0A0D