Search code examples
c#winformseventscombobox

WinForms ComboBox detect if item was selected - even if item is the same


The question is similar to What event handler to use for ComboBox Item Selected (Selected Item not necessarily changed) , albeit with WinForms.

When the user selects an item in a ComboBox, even if the item was selected before, I want to execute some additional code. If the user just opens and closes the dropdown, I don't want the code to run.

SelectionChanged, ValueChanged and DropDownClosed so far did not work. ValueChanged is best, but not 100%ly what I want. I would like a ValueSelected event.


Solution

  • WinForms' ComboBox raises the SelectedIndexChanged and SelectionChangeCommitted events anytime an item is selected, not matter if it is the same index.
    These events are not raised if the DropDown is simply opened and closed.