-2

I have a little problem when loading a ComboBox.

The question is that in the phase of loading data, the default selectedIndex event fires.

How can I prevent this during the load process?

Apalabrados
  • 1,098
  • 8
  • 21
  • 38
  • 2
    Possible duplicate of [Stop comboBox's selectedIndexChanged event from firing when the form loads](http://stackoverflow.com/questions/3263240/stop-comboboxs-selectedindexchanged-event-from-firing-when-the-form-loads) – emerson.marini Jun 14 '16 at 10:53
  • Possible duplicate of [How to prevent selectedindexchanged event when DataSource is bound?](http://stackoverflow.com/questions/14111879/how-to-prevent-selectedindexchanged-event-when-datasource-is-bound) – emerson.marini Jun 14 '16 at 10:54
  • And many more. Just do a quick search and you'll find them. – emerson.marini Jun 14 '16 at 10:54

2 Answers2

3

I suggest to use a global variable

Boolean isLoaded = false;

in your selectedIndexChange add this code

if(!isLoaded)
{
isLoaded = true;
}
else
{
 /// write your code here 
}
0

I would remove the event and re add it after the loading of the data is completed.

    combo.SelectedIndexChanged -= combo_SelectedIndexChanged;
    //Do the loading of the data into the combo
    combo.SelectedIndexChanged += new EventHandler(combo_SelectedIndexChanged);
simon Whale
  • 61
  • 2
  • 7