Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comobox event SelectedValueChanged

i have simple question may be someone asked it before me but i could not find it.Let say i have datatable that has some data from the database and i want to bind it to a combobox i use standart code like this

 comboBox1.BeginUpdate( );
 comboBox1.ValueMember = "id";
 comboBox1.DisplayMember = "name";
 comboBox1.DataSource = dt;
 comboBox1.EndUpdate( );

The problem is during this binding the event SelectedValueChanged is fired.The problem is that rebind combo several times when outher values change and every time i must do sometihn like this

 comboBox1.SelectedIndexChanged -= new System.EventHandler( this.comboBox1_SelectedValueChanged );

my question is there a smarter way to skip the event when i comes from databinding not from user input.The problem is that i want to do it some how globaly in my control that inherits combobox and not to do it everytime in every from Best Regards,
Iordand

like image 269
IordanTanev Avatar asked May 08 '10 06:05

IordanTanev


People also ask

Which is the default event of combobox control?

By default, DropDownStyle property of a Combobox is DropDown. In this case user can enter values to combobox. When you change the DropDownStyle property to DropDownList, the Combobox will become read only and user can not enter values to combobox.

Which event can be used to detect changes in list combo box selection?

You can use "ComboBoxItem. PreviewMouseDown" event.

What is selected index changed in C#?

The SelectedIndexChanged event occurs when the SelectedIndex has just changed. The SelectedIndexChanged event does not fire unless the AutoPostBack property is True . The SelectedIndexChanged event handler receives two arguments: The RadDropDownList that is loading items.

What event from this class fires when the user of the control chooses an item from the combobox?

The combo box fires an action event when the user selects an item from the combo box's menu.


1 Answers

Try using the SelectionChangeCommitted event.

From MSDN documentation:

SelectionChangeCommitted is raised only when the user changes the combo box selection. Do not use SelectedIndexChanged or SelectedValueChanged to capture user changes, because those events are also raised when the selection changes programmatically.

like image 90
jim31415 Avatar answered Sep 19 '22 08:09

jim31415