If combobox selected then show

Weblover picture Weblover · Aug 12, 2014 · Viewed 15.1k times · Source

I have to load a form and in this form I want to hide certain labels and text-boxes. In addition I want to show labels and text-boxes matching the conditionif combo-box selected =="Something"

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (comboBox1.Text == "Something")
    {
        label1.Show();
        label2.Show();
        textBox1.Show();
        textBox2.Show();
    }
}

How do I get these labels and text-boxes shown after I had selected a combo-box

Answer

S.L. picture S.L. · Aug 12, 2014

try

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    if (comboBox1.SelectedValue == "Something")
    {
        label1.Visible = true;
        label2.Visible = true;
        textBox1.Visible = true;
        textBox2.Visible = true;
    }
}