Reputation: 13313
I have a ComboBox
control with the DropDownStyle
properties set to DropDownList
.
Once there is an item selected, how can I clear the selection from the ComboBox
without deleting any Items in it ?
I'd normally use something like that:
myComboBox.Text.Clear();
But I can't do that. Any idea how I could clear it ?
Upvotes: 36
Views: 150018
Reputation: 377
Try specifying the actual index of the item you want erase the text from and set its Text
equal to ""
.
myComboBox[this.SelectedIndex].Text = "";
or
myComboBox.selectedIndex.Text = "";
I don't remember the exact syntax but it's something along those lines.
Upvotes: -2
Reputation: 1
comboBox1.Text = " ";
This is the best and easiest way to set your comboBox
back to default settings without erasing the contents of the comboBox
.
Upvotes: -1
Reputation:
Try this, if you populate your Combobox with objects:
Combobox.SelectedItem = null;
Upvotes: 0
Reputation: 1
In c# if you make you comboBox configuration style DropDownList
or DropDown
then use both of them in this method to clear.
ComboBox1.SelectedIndex = -1;
Upvotes: -1
Reputation: 1
The following code will work:
ComboBox1.SelectedIndex.Equals(String.Empty);
Upvotes: -3
Reputation: 39
all depend on the configuration. for me works
comboBox.SelectedIndex = -1;
my configuration
DropDownStyle: DropDownList
(text can't be changed for the user)
Upvotes: 3
Reputation: 1
write the following code:
comboBox1.Items[comboBox1.SelectedIndex] = string.Empty;
Upvotes: -2
Reputation: 472
The only way I could get it to work:
comboBox1.Text = "";
For some reason ionden's solution didn't work for me.
Upvotes: 24
Reputation: 12776
You could change SelectedIndex
property:
comboBox1.SelectedIndex = -1;
Upvotes: 85