Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop comboBox's selectedIndexChanged event from firing when the form loads

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?

like image 569
StackTrace Avatar asked Jul 16 '10 08:07

StackTrace


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.

How do you prevent SelectedIndexChanged event when datasource is bound?

You may use Tag property of combobox. It can be empty or 0 integer value when it's empty or have not fulfilled yet. You have to set combobox's Tag as count of it's items after bounding. In SelectedValueChanged event if the Tag property is null or 0 you have to return from void.

How do I use SelectedIndexChanged?

The SelectedIndexChanged event of ASP.Net DropDownList When an item is changed in ASP.Net DropDownList, the following OnSelectedIndexChanged event handler is executed. Inside the event handler, the selected Text and Value of the DropDownList Selected Item is fetched and displayed using JavaScript Alert message box.


1 Answers

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.

like image 68
arbiter Avatar answered Oct 21 '22 08:10

arbiter