C# – event of selecting a item in combobox

ccomboboxeventstextboxvisible

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!

Best Answer

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