Combo Box if statement

Vulegend picture Vulegend · Jun 23, 2012 · Viewed 63.8k times · Source

I am having a problem with a combo box here. What I did is made a combo box, added items using comboBox1.Items.Add("Something");. Now I made a text box down there and what I need is when I select something from the combo box the text box changes according to selected item on combo box. What I thought it would do is

if(comboBox1.SelectedItem.ToString() == "Something")
{
    textBox1.Text = "Something";
}

But it's not working for some reason, I tried both without ToString() and with still it is not working.

Answer

Darren picture Darren · Jun 23, 2012

Try using: comboBox1.SelectedText

if(comboBox1.SelectedText == "Something")
{
      textBox1.Text = "Something";
}