How do I clear a combobox?

前端 未结 16 1748
醉梦人生
醉梦人生 2020-12-04 18:55

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 boxe

相关标签:
16条回答
  • 2020-12-04 19:25

    You can use

    Cbo.Items.Clear();
    

    or

    Cbo.DataSource = null;
    

    if you have a binding on it.

    0 讨论(0)
  • 2020-12-04 19:27
    cboxHour.Items.Clear();
    

    this works

    0 讨论(0)
  • 2020-12-04 19:28

    Mine worked with:

    ComboBox.removeAllItems();
    

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

    0 讨论(0)
  • 2020-12-04 19:28

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

    comboBox1.SelectedIndex = -1;
    comboBox1.Items.Clear();
    
    0 讨论(0)
  • 2020-12-04 19:30

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

    Combobox.Text = "Select...";
    
    0 讨论(0)
  • 2020-12-04 19:31

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

    cboxHour.SetSelectedIndex(-1);
    
    0 讨论(0)
提交回复
热议问题