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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Combo Box slected index changed

Combo Box slected index changed

Scheduled Pinned Locked Moved C#
helpdatabasequestion
4 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.
  • M Offline
    M Offline
    msx23
    wrote on last edited by
    #1

    Hi, I'm playing around with a form and I want it to know if I've changed the contents of a combo box (selecting a new index that is, it doesn't take text extry) placed on it. So I just made a global bool variable 'ComboBoxChanged' initialized as FALSE, and I set it to TRUE upon handling the ComboBox.SelectedIndexChanged event. The problem I have is that the event is triggered when the form is loaded, thus setting my 'ComboBoxChanged' variable event though I haven't actually selected a new index. What do you guys think is the best solution to this? Thanks for any help.

    C D D 3 Replies Last reply
    0
    • M msx23

      Hi, I'm playing around with a form and I want it to know if I've changed the contents of a combo box (selecting a new index that is, it doesn't take text extry) placed on it. So I just made a global bool variable 'ComboBoxChanged' initialized as FALSE, and I set it to TRUE upon handling the ComboBox.SelectedIndexChanged event. The problem I have is that the event is triggered when the form is loaded, thus setting my 'ComboBoxChanged' variable event though I haven't actually selected a new index. What do you guys think is the best solution to this? Thanks for any help.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Don't use global varuables ?

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      • M msx23

        Hi, I'm playing around with a form and I want it to know if I've changed the contents of a combo box (selecting a new index that is, it doesn't take text extry) placed on it. So I just made a global bool variable 'ComboBoxChanged' initialized as FALSE, and I set it to TRUE upon handling the ComboBox.SelectedIndexChanged event. The problem I have is that the event is triggered when the form is loaded, thus setting my 'ComboBoxChanged' variable event though I haven't actually selected a new index. What do you guys think is the best solution to this? Thanks for any help.

        D Offline
        D Offline
        darkelv
        wrote on last edited by
        #3

        When the combo box is being populated, the selected index changed is fired on every item (don't ask me why). So you may need another form wide variable or in your inherited combo box to keep track of whether the combo box is being populated.

        1 Reply Last reply
        0
        • M msx23

          Hi, I'm playing around with a form and I want it to know if I've changed the contents of a combo box (selecting a new index that is, it doesn't take text extry) placed on it. So I just made a global bool variable 'ComboBoxChanged' initialized as FALSE, and I set it to TRUE upon handling the ComboBox.SelectedIndexChanged event. The problem I have is that the event is triggered when the form is loaded, thus setting my 'ComboBoxChanged' variable event though I haven't actually selected a new index. What do you guys think is the best solution to this? Thanks for any help.

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          An easy work around for this is to set enabled to false before populating it then to true when it's finished. You can then check the enabled state in the SelectedIndexChanged and only alter your global variable if Enabled == true;

          Dave

          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