Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
695 views
in Technique[技术] by (71.8m points)

winforms - 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?

question from:https://stackoverflow.com/questions/65898764/how-to-make-a-textbox-visible-if-last-item-in-a-combobox-is-selected-c-sharp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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;
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...