Click here to Skip to main content
15,844,498 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to use SelectedIndexChanged?

I set a Combobox in my WindowsForm.
Then, if I use my mouse to select the item on the dropdownlist on Combobox, any problem happens.
But I use keybord to select the item on the combobox, SelectedIndexChanged event happens in everytime when I put the down key(also up key).

I want to make my event happens when I decided the selection on the Combobox.
Any suggestion is OK.
BillWoodruff 6-Dec-15 8:31am    
Please show the code you are using, specifically, the handlers for the Events of the ComboBox you have defined.

"any problem happens:" we need to know exactly what happens; is there an error message ? if so, what is it.
Richard MacCutchan 6-Dec-15 8:32am    
Any suggestion is OK

You first need to explain what the problem is. Saying "any problem happens" does not tell us anything.
DotNetSteve 6-Dec-15 14:31pm    
The way I am reading this, i don't think there is a problem. In the one case you are using the mouse and going directly to the item. With the keyboard you are stepping through each item and thus firing an even for each word you are stepping through. You could put some type of timer (like a debounce circuit) that only fires when the event timer finally fires.
BillWoodruff 7-Dec-15 4:17am    
Is this a WinForms Project ? Would disabling the arrow-keys when the ComboBox is used work for you ? Would only using the selected item in the ComboBox when the user has pressed the 'Return key work for you ?

Take a look at the SelectionChangeCommitted event. This fires on user initiated selection changes but not when the dropdown is open.

Be aware that it does not fire for programmatic selection changes. So code such as
combo.SelectedIndex = someNewIndexValue; will fire SelectedIndexChanged but not SelectionChangeCommitted.

Share this answer
cocrie 5-Jan-19 4:37am    
Thank you very much.
You can use the DropDownClosed event instead.
It will only fire when the dropdown list is closed. The you check the SelectedItem.

private void comboBox1_DropDownClosed(object sender, EventArgs e)
    // Convert to to what ever type you have stored
    MyType obj = (MyType)comboBox1.SelectedItem;  
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900