Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Combobox SelectedIndexChanged Infinite Loop

Combobox SelectedIndexChanged Infinite Loop

Scheduled Pinned Locked Moved Visual Basic
questiondatabase
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hypermommy
    wrote on last edited by
    #1

    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

    T B 2 Replies Last reply
    0
    • H Hypermommy

      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

      T Offline
      T Offline
      Tom Deketelaere
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • H Hypermommy

        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

        B Offline
        B Offline
        binjafar
        wrote on last edited by
        #3

        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!

        H 1 Reply Last reply
        0
        • B binjafar

          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!

          H Offline
          H Offline
          Hypermommy
          wrote on last edited by
          #4

          SelectionChangeCommitted was exactly what I need!! Thanks!!!!! Never even knew that it existed but it's just what I needed.

          Denise "Hypermommy" Duggan

          B 1 Reply Last reply
          0
          • H Hypermommy

            SelectionChangeCommitted was exactly what I need!! Thanks!!!!! Never even knew that it existed but it's just what I needed.

            Denise "Hypermommy" Duggan

            B Offline
            B Offline
            binjafar
            wrote on last edited by
            #5

            Enjoy! :)

            H 1 Reply Last reply
            0
            • B binjafar

              Enjoy! :)

              H Offline
              H Offline
              Henry Minute
              wrote on last edited by
              #6

              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.”

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups