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?
views:
82answers:
3
+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
2010-07-16 08:50:48
+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
2010-07-16 19:16:48
@arbiter: Nice solution, i will try it. seems to be better than my answer.
Shantanu Gupta
2010-07-19 05:29:27
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
2010-07-16 19:20:27