Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent selectedindexchanged event when DataSource is bound?

Tags:

I have ComboBox control(WinForm project).

When I bind DataSource to the ComboBox control combobox_selectedindexchanged event is fired.

Any idea how to prevent selectedindexchanged event when DataSource is bound?

like image 249
Michael Avatar asked Jan 01 '13 16:01

Michael


People also ask

How do you stop a combobox SelectedIndexChanged event from firing when the form loads?

You can simply unbind the SelectedIndexChanged event, call your fill function and bind the SelectedIndexChanged event again.


1 Answers

Remove the handler for the SelectedIndex_Changed event, bind your data, then add the handler back. Following is a simple example of how this might be done within a method:

private void LoadYourComboBox() {     this.comboBox1.SelectedIndexChanged -= new EventHandler(comboBox1_SelectedIndexChanged);           // Set your bindings here . . .       this.comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged); } 
like image 107
XIVSolutions Avatar answered Oct 13 '22 21:10

XIVSolutions