[c#] Clear ComboBox selected text

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 ?

This question is related to c# winforms drop-down-menu combobox

The answer is


all depend on the configuration. for me works

comboBox.SelectedIndex = -1;

my configuration

DropDownStyle: DropDownList

(text can't be changed for the user)


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;

comboBox1.Text = " ";

This is the best and easiest way to set your combo box back to default settings without erasing the contents of the combo box.


Try specifying the actual index of the item you want erase the text from and set it's 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.


write the following code:

comboBox1.Items[comboBox1.SelectedIndex] = string.Empty;

The only way I could get it to work:

comboBox1.Text = "";

For some reason ionden's solution didn't work for me.


The following code will work:

ComboBox1.SelectedIndex.Equals(String.Empty);

This is what you need:

comboBox1.ResetText();


nameofcombobox.SelectedItem=-1;

Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to winforms

How to set combobox default value? Get the cell value of a GridView row Getting the first and last day of a month, using a given DateTime object Check if a record exists in the database Delete a row in DataGridView Control in VB.NET How to make picturebox transparent? Set default format of datetimepicker as dd-MM-yyyy Changing datagridview cell color based on condition C# Inserting Data from a form into an access Database How to use ConfigurationManager How to implement drop down list in flutter? How can I create a dropdown menu from a List in Tkinter? How can I close a dropdown on click outside? Making a drop down list using swift? HTML: Select multiple as dropdown How to get selected value of a dropdown menu in ReactJS Avoid dropdown menu close on click inside Bootstrap 3 dropdown select How to make a drop down list in yii2? Android custom dropdown/popup menu

Examples related to combobox

How to set combobox default value? PHP code to get selected text of a combo box How to add items to a combobox in a form in excel VBA? How add items(Text & Value) to ComboBox & read them in SelectedIndexChanged (SelectedValue = null) Get Selected value of a Combobox jQuery "on create" event for dynamically-created elements How to get the selected item of a combo box to a string variable in c# HTML combo box with option to type an entry twitter bootstrap autocomplete dropdown / combobox with Knockoutjs C# winforms combobox dynamic autocomplete