Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Forms how to find out if selectedindex was changed by user or by code

Tags:

c#

.net

winforms

I have a combobox in a Windows Forms project with an event attached to the selectedindex changed event. The event is getting triggered when the selectedindex is changed both from code and from user input. How do you detect if the selectedindex is getting changed due to user input?

like image 816
runxc1 Bret Ferrier Avatar asked Nov 19 '10 02:11

runxc1 Bret Ferrier


1 Answers

Can you use the SelectionChangeCommitted event instead?

SelectionChangeCommitted is raised only when the user changes the combo box selection

EDIT: The SelectionChangeCommitted event has a major failing: if you use F4 to drop down the list then mouse over your selection and use the Tab key to go to the next control, it does not fire.

There's a [closed and deleted] bug on Connect about it, which suggests using the DropDownClosed event as well to catch this edge case.

like image 193
stuartd Avatar answered Sep 28 '22 07:09

stuartd