Reputation: 11
I have a combobox with dropdown style and 2 text boxes. I want to add a condition that if the string of either of the 2 text boxes are not null than the combobox should get reset if any item is selected from it.
I'm using combobox.SelectedIndex=-1
in my if clause but it does not work I guess because I'm using it in a wrong event.
Upvotes: 1
Views: 9182
Reputation: 138
Same as clearselection in c# the command for WF is
combobox.ResetText()
Upvotes: 0
Reputation: 1631
Try This
combobox.Items.Clear();
or
combobox.DataSource = null;
I hope you managing you Text_Changed event well , cause you have not posted that code
Upvotes: 1
Reputation: 1246
Make sure that both your textboxes are using the TextChanged event, and then point them to the same method. If both boxes are not null, then the combobox will reset. If you want it to be one or the other, just changed the && to ||
private void TextBox_TextChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox1.Text) && !string.IsNullOrEmpty(textBox2.Text))
{
comboBox1.SelectedIndex = -1;
}
}
Upvotes: 1