Reputation: 1159
I have a combo box and textbox in form, (in windows form platform), the textbox visible is false by default, I want to show (visible=true) the the textbox when the specific item of combo box selected.
which event of combobox is suitable for this work!
Upvotes: 0
Views: 7242
Reputation: 1
This Code will definitely help you.
if (comboBox2.Text.ToString() == "Desired Value")
comboBox1.Visible = true;
else
comboBox1.Visible = false;
Upvotes: 0
Reputation: 1286
if you're depending on a fixed index in the combo box items use SelectedIndexChange event
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == yourindex)
textBox1.Visible = true;
else
textBox1.Visible = false;
}
if you're depending on combo box selected item value use SelectedValueChanged event
private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedValue.ToString() == "yourvalue")
textBox1.Visible = true;
else
textBox1.Visible = false;
}
Upvotes: 2
Reputation: 32681
use the combobox SelectedIndexChange event or Selecton Change Committedand in that event check for the selectedvalue of your combobox like
if(combobox1.SelectedValue == desiredvalue)
textBox1.Visible = true;
Upvotes: 0