1.11M Members

Need to prevent combobox selection

 
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!

 
0
 

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

Combobox1.SelectionIndex = -1
 
0
 

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.

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