Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding a dropdown in C#

I want to create a checkbox, If that is checked then it should display the dropdown. If not checked then it should hide the dropdown. This is how my code looks in Form.Designer.cs file.

        this.comboBox2.FormattingEnabled = true;
        this.comboBox2.Items.AddRange(new object[] {
        "Database 1",
        "Database 2",
        "Database 3"});
        this.comboBox2.Location = new System.Drawing.Point(165, 436);
        this.comboBox2.Name = "comboBox2";
        this.comboBox2.Size = new System.Drawing.Size(150, 21);
        this.comboBox2.TabIndex = 13;
        this.comboBox2.Text = "Database";

and My checkbox code in other file is

 if  (checkBox1.CheckState == CheckState.Checked)
        {

        }
like image 820
Jaspreet Deol Avatar asked Feb 09 '26 20:02

Jaspreet Deol


2 Answers

Use Visible

this.comboBox2.Visible = false;

Which would hide comboBox2.

like image 191
Darren Avatar answered Feb 15 '26 12:02

Darren


if (checkbox1.CheckState == CheckState.Checked)
{
 this.combobox2.Visible = True;
}

else (checkbox1.CheckState == CheckState.Unchecked)
{
 this.combobox2.Visible = False;
}
like image 25
Philip Gullick Avatar answered Feb 15 '26 13:02

Philip Gullick