简体   繁体   中英

How to make a textbox visible if last item in a combobox is selected c#

I have combobox9,textBox4 and textBox15 in a winform. By default, textBox15 is hidden.

What i'm trying to do.

If textbox4 backcolor is red and the last item in combobox9 is selected, then show textbox15.

         if (comboBox9.SelectedIndex == comboBox9.Items.Count - 1  && textBox4.BackColor == Color.Red) ;

            {
                textBox15.Visible = true;

                textBox15.BackColor = Color.Red;
            }

            
            else
            {

                textBox15.Visible = false;
            }

No errors, it just doesn't work as expected. It keeps the textbox hidden even when the conditions are satisfied. Any leads?

You should put all your code in your SelectedIndexChanged event of your combobox

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    if(comboBox1.SelectedIndex == comboBox1.Items.Count - 1)
    {
        label1.Visible = true;
    }
    else
    {
        label1.Visible = false;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM