1,105,320 Community Members

Need to prevent combobox selection

Member Avatar
Junior Poster in Training
97 posts since Oct 2010
Reputation Points: 2 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]

I have a windows form that has 4 comboboxes inside. These 4 boxes are linked, in that when the first box receives user selected data, the second box populates. When the second box receives user selected data, the third box populates. At least that is how I want this to happen. Instead, when the form loads, the first box populates, and so the SelectedIndexChanged event is thrown. This triggers the second combobox, and subsequently the third. Is there a way to keep this from happening? Of course, the first combobox will be populated with the form_load, but to keep the others from populating?

Any ideas are appreciated! Thanks!

Member Avatar
Senior Poster
3,543 posts since Nov 2007
Reputation Points: 987 [?]
Q&As Helped to Solve: 542 [?]
Skill Endorsements: 74 [?]

Try to set Combobox SelectionIndex = -1 to make it not select any items on Form Load event.

Combobox1.SelectionIndex = -1
Member Avatar
Reverend Jim
Noli mentula
5,404 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 647 [?]
Skill Endorsements: 51 [?]

Or you could have a class level variable like

Private Initializing As Boolean = True

and set it to False at the end of the initialization. Then in your SelectedIndexChanged events you could do

If Initializing Then Exit Sub

That would prevent those events from processing until the initialization is done.

This article has been dead for over three months: Start a new discussion instead
Start New Discussion
View similar articles that have also been tagged: