I have a windows form with 2 comboboxes. The first combobox is visible while the other is not, until when I select a value in the first combobox, the second combobox will appear. How do I do that?
Printable View
I have a windows form with 2 comboboxes. The first combobox is visible while the other is not, until when I select a value in the first combobox, the second combobox will appear. How do I do that?
Handle the SelectedIndexChanged event of the first ComboBox:Code:private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.comboBox2.Visible = (this.comboBox1.SelectedIndex != -1);
}
Thanks for your reply, but it doesn't work. I first set the visible property of the second combobox to false and added your code, but it doesn't work. The second combobox had appeared when the form loads. How?
You can see from the code that the second ComboBox is visible if an item is selected in the first ComboBox and not visible if an item isn't selected. Assuming that you've set the Visible property of the second ComboBox to False in the designer, if your second ComboBox is visible then you have an item selected in your first ComboBox, plain and simple.