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.

1

18 Answers

Did you try cboxHour.Items.Clear()?

4

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

cboxHour.SelectedIndex = -1
1

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();
1

You can use

Cbo.Items.Clear();

or

Cbo.DataSource = null;

if you have a binding on it.

0

Answer for your question is:

metroComboBox1.SelectedItem = null;
anycomboBox1.SelectedItem=null;
3
cboxHour.Items.Clear();

this works

1

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();

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

cboxHour.SetSelectedIndex(-1);

Use:

comboBox1.ResetText();

and it's done.

Docs: ComboBox.ResetText Method (Namespace: System.Windows.Forms)

1

Mine worked with:

ComboBox.removeAllItems();

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

0

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();
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");
}

In WPF You can try this code

cbHours.Items.Clear();

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

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

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

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

> Its work for me:

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

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;

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

Combobox.Text = "Select...";
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi

Maya Lin-Takahashi

Consumer Tech & Gadget Reviewer

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.

Share this article
Twitter Facebook Pinterest