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.
Try using:
comboBox1.SelectedText
if(comboBox1.SelectedText == "Something")
{
textBox1.Text = "Something";
}
Double click on your combobox and it will generate event for you(SelectedIndexChanged
by default). put your code inside that generated event. When you change combobox selected value then you can see the text box value change accordingly.
if you need to show combobox selected value in the textbox, you can put below code inside generated event
textBox1.Text = comboBox1.SelectedItem.ToString();
Oh found the problem . I was putting the code in wrong section (on textBOx_click) section :P
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With