SelectedIndexChanged - How do you test this only when user clicks it

emaduddeen

Well-known member
Joined
May 5, 2010
Messages
171
Location
Lowell, MA & Occasionally Indonesia
Programming Experience
Beginner
Hi Everyone,

I have a combo box and use the SelectedIndexChanged event. I noticed when I assign a value to the combo box that this event fires even though the user does not click on the control.

Can you tell me how to test for when the user clicks on it and actually selects a value from it?

Thanks.

Truly,
Emad
 
That ability isn't built into the ComboBox so you'll need to code for it yourself. Add a class level Boolean and set it to False. In the SelectedIndexChanged event check that boolean for a false and if so, run your current code otherwise set it to false. Then when you change the index in code set the boolean to true.
 
Learn something new everyday, I've never seen that event listed. Turns out it existed in .Net since FW 1.0 and I never even knew it. Too bad the ListBox doesn't have that event
 
That ability actually is built into the ComboBox. Handle the SelectionChangeCommitted event instead of SelectedIndexChanged.

Hi,

Thanks for the information.

I tried SelectionChangeCommitted but I get the errors shown in the attachment. It's also not one of the events in the properties panel either. Can you tell me how to get VB 2008 to recognize it?

Thanks.

Truly,
Emad
 

Attachments

  • SelectionChangeCommitted.jpg
    SelectionChangeCommitted.jpg
    341.6 KB · Views: 33
This works....

All I did was add a combobox, added code in the form's load event to give the combobox items and handled the event, then ran it and there it was working like normal
 

Attachments

  • WindowsApplication1.zip
    14.8 KB · Views: 20
Back
Top