Combobox SelectedIndexChanged Infinite Loop
-
I have a combobox on my form called cboLang. When the selectedindexchanged fires I run a routine that goes out to the database and changes the labels to the language requested. Then it loads up the combobox with that language's form of the name of each possible language (i.e., if the user selected French it would put "Anglais" in the combobox instead of "English"). What I'd like to do next is ensure that the language the user selected is the one selected in the combobox. However, whenever I do this it fires the selectedindexchanged event again which starts everything all over and it gets into an infinite loop. How can I set the selected item without it firing the selectedindexchanged event?
Denise "Hypermommy" Duggan
-
I have a combobox on my form called cboLang. When the selectedindexchanged fires I run a routine that goes out to the database and changes the labels to the language requested. Then it loads up the combobox with that language's form of the name of each possible language (i.e., if the user selected French it would put "Anglais" in the combobox instead of "English"). What I'd like to do next is ensure that the language the user selected is the one selected in the combobox. However, whenever I do this it fires the selectedindexchanged event again which starts everything all over and it gets into an infinite loop. How can I set the selected item without it firing the selectedindexchanged event?
Denise "Hypermommy" Duggan
2 possible solutions that I see: 0) Don't do the code that changes everything in the 'selectedindexchanged' event. Do it in a 'Save settings' button or so. 1) Maintain a boolean variable 'ImWorking' (dummy name :) ) (on form level). While your code is running change this boolean to 'True'. First thing in your 'selectedindexchanged' event is check this boolean. If the boolean is true than exit the event (exit sub) My choice would be first one. This allows for the user to misclick without having to wait for the language change to have ran its course.
-
I have a combobox on my form called cboLang. When the selectedindexchanged fires I run a routine that goes out to the database and changes the labels to the language requested. Then it loads up the combobox with that language's form of the name of each possible language (i.e., if the user selected French it would put "Anglais" in the combobox instead of "English"). What I'd like to do next is ensure that the language the user selected is the one selected in the combobox. However, whenever I do this it fires the selectedindexchanged event again which starts everything all over and it gets into an infinite loop. How can I set the selected item without it firing the selectedindexchanged event?
Denise "Hypermommy" Duggan
You have possibly two ways to do this... 1. use SelectionChangeComitted event (recommended) 2. use some global variable Flag that u set to 'true' once all the comboBox is filled up... before comboBox is completely filled..this flag should remain 'false'... later on in ur code... just check if the flag is set to 'true' before doing what ever u do upon item selection. Enjoy!
-
You have possibly two ways to do this... 1. use SelectionChangeComitted event (recommended) 2. use some global variable Flag that u set to 'true' once all the comboBox is filled up... before comboBox is completely filled..this flag should remain 'false'... later on in ur code... just check if the flag is set to 'true' before doing what ever u do upon item selection. Enjoy!
SelectionChangeCommitted was exactly what I need!! Thanks!!!!! Never even knew that it existed but it's just what I needed.
Denise "Hypermommy" Duggan
-
SelectionChangeCommitted was exactly what I need!! Thanks!!!!! Never even knew that it existed but it's just what I needed.
Denise "Hypermommy" Duggan
-
An excellent solution. I too was unaware of this event. :thumbsup::thumbsup:
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”