'How do I clear a combobox?

I have some combo-boxes that are set up as drop down lists, and the user can pick a number in them. I also have a Clear button that should clear the text from the combo boxes but I can't seem to get it. I've tried:

 //doesn't work
 cboxHour.Text = "";

and

//doesn't work
cboxHour.ResetText();

This seems like it should be so straight forward but I'm just not getting it.



Solution 1:[1]

If you just want to clear the current selection, but leave all of the items in the list, you can use:

cboxHour.SelectedIndex = -1

Solution 2:[2]

When ComboBox is not data-bound, I've found I need both: Clear() removes the items but still leaves the SelectedItem's text, while ResetText() removes that text. VS2008.

ComboBox.Items.Clear();
ComboBox.ResetText();

Solution 3:[3]

You can use

Cbo.Items.Clear();

or

Cbo.DataSource = null;

if you have a binding on it.

Solution 4:[4]

Answer for your question is:

metroComboBox1.SelectedItem = null;
anycomboBox1.SelectedItem=null;

Solution 5:[5]

cboxHour.Items.Clear();

this works

Solution 6:[6]

If you have applied datasource to combobox, then it will not be cleared as cmb.Items.Clear().

For that you have to assign datasource null to combobox.

cmb.DataSource = null;
cmb.Items.Clear();

Solution 7:[7]

If there is value binding part for your combobox. Use below code to clear its value:

cboxHour.SetSelectedIndex(-1);

Solution 8:[8]

Use:

comboBox1.ResetText();

and it's done.

Docs: ComboBox.ResetText Method (Namespace: System.Windows.Forms) https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.combobox.resettext?view=netframework-4.8

Solution 9:[9]

Mine worked with:

ComboBox.removeAllItems();

If it doesn't read that well its, remove all items.

Solution 10:[10]

Combo Box, DropDown all are having the same logic to clear/remove all items from them and it is like below.

//For checkbox list
cblTest.Items.Clear();

//For drop down list
ddlTest.Items.Clear();

Solution 11:[11]

private void Resetbtn_Click(object sender, EventArgs e)
{    
    comboBox1.Items.Clear(); // it will clear a combobox

    comboBox1.Items.Add("Student"); //then add combobox elements again. 
    comboBox1.Items.Add("Staff");
}

Solution 12:[12]

In WPF You can try this code

cbHours.Items.Clear();

Solution 13:[13]

You can try the below option for clearing the selected text and all items from the ComboBox.

comboBox1.SelectedIndex = -1;
comboBox1.Items.Clear();

Solution 14:[14]

This worked for me when I added ComboBox.Focus()

ComboBox.Items.Clear();
ComboBox.ResetText();
ComboBox.Focus();

Solution 15:[15]

> Its work for me:

    ComboCapacity.DataSource = null;
    ComboCapacity.Items.Clear();
    ComboCapacity.ResetText();
                    

Solution 16:[16]

My Soluce to Clear DropDownList ComboBox C# VS2022

ComboBox _ComboBox = new ComboBox();
_ComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
_ComboBox.DataSource = DataTablexxx;
_ComboBox.DisplayMember = "xxxx";
_ComboBox.ValueMember = "Idn";
//Enable the form now
this.Visible = true;
this.ResumeLayout(false);
this.PerformLayout();
//Select the item by ident saved
_ComboBox.SelectedValue = Properties.Settings.Default.Idn;  

On Event Button :

_ComboBox.SelectedIndex = -1;
_ComboBox.SelectedItem = null;

Solution 17:[17]

I have just changed the text of the combobox, like this:

Combobox.Text = "Select...";