Home > Blockchain >  Changing value of label with combobox
Changing value of label with combobox

Time:11-22

This is probably a really basic question, but I'm been out of programming for a few years so here it goes. I'm trying to make a combobox with certain values and when I press one of the values, I want labels to change their values.

Lets say I have a value "TEST" in the combobox, when selected, I want the label lblHeight to be changed to "TEST". I code I've tried is below, but I can't understand why it doesn't work. Can someone help?

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (comboBox1.SelectedText == "TEST")
        {
            lblHeight.Text = "TEST";
        }
    }

CodePudding user response:

Try using SelctedItem instead of SelectedText, like this:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (comboBox1.SelectedItem.ToString() == "TEST")
    {
        lblHeight.Text = "TEST";
    }
}
  • Related