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. C#
  4. Value of label is not changing upon loading or changing the value of the combobox

Value of label is not changing upon loading or changing the value of the combobox

Scheduled Pinned Locked Moved C#
question
3 Posts 3 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.
  • J Offline
    J Offline
    jon 80
    wrote on last edited by
    #1

    Why isn't the following changing the value of the label LanguageSpoken?

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
    LanguageSpoken.Text = cboUserLanguage.SelectedText;
    }

        private void Form1\_Load(object sender, EventArgs e)
        {
            cboUserLanguage.SelectedIndex = 0;
            LanguageSpoken.Text = cboUserLanguage.SelectedText;
        }
    

    Jon

    L F 2 Replies Last reply
    0
    • J jon 80

      Why isn't the following changing the value of the label LanguageSpoken?

      private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
      {
      LanguageSpoken.Text = cboUserLanguage.SelectedText;
      }

          private void Form1\_Load(object sender, EventArgs e)
          {
              cboUserLanguage.SelectedIndex = 0;
              LanguageSpoken.Text = cboUserLanguage.SelectedText;
          }
      

      Jon

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      cboUserLanguage.SelectedIndex = 0;

      Put a breakpoint on that line, and see what the SelectedIndex is before the assignment. If it is already 0 (could be set in the designer), then there will not be a "change".

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] They hate us for our freedom![^]

      1 Reply Last reply
      0
      • J jon 80

        Why isn't the following changing the value of the label LanguageSpoken?

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
        LanguageSpoken.Text = cboUserLanguage.SelectedText;
        }

            private void Form1\_Load(object sender, EventArgs e)
            {
                cboUserLanguage.SelectedIndex = 0;
                LanguageSpoken.Text = cboUserLanguage.SelectedText;
            }
        

        Jon

        F Offline
        F Offline
        Freak30
        wrote on last edited by
        #3

        Look here. Seems that there are problems when using it in click handler. I suggest using cboUserLanguage.Items[cboUserLanguage.SelectedIndex].ToString(); instead.

        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