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
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
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.
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
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
 

emaduddeen

Well-known member
Joined
May 5, 2010
Messages
171
Location
Lowell, MA & Occasionally Indonesia
Programming Experience
Beginner
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: 32

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
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: 17

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
Hi JuggaloBrotha,

I see you are using VS 2010 on Windows7. I also have Windows7 64 bit Home Premium.

When you installed VS 2010, did you have any problems converting your VB 2008 applications?

Truly,
Emad
I haven't converted any projects to VS 2010 yet, but I have from 2003 to 2005 and from 2003 to 2008 before those worked fine, I can't think of a reason why VS 2010 wouldn't work as it just updates the xml nodes in the project & solution files.

I just happen to have VS 2010 installed and I've used it for a project a friend sent me, I use VS 2008 for primary development.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,397
Location
Sydney, Australia
Programming Experience
10+
Delete that method and use the drop-down lists at the top of the code window. Select the control on the left and then the event on the right. Is SelectionChangeCommitted list for that control? Is that control definitely a ComboBox?
 
Top Bottom