.netwinformscompact-framework

Clear combobox datasource items


Combobox datasource has been assigned with

cmbCombobox.DataSource = myCollection

where myCollection has type MyCollection: List

How can I clear items in combobox?


Solution

  • When you data bind a control, it will synchronize with that collection. In order to clear the items in your ComboBox set it's DataSource to null.

    cmbComboBox.DataSource = null;
    

    If your combobox is not databound (no DataSource) then you can do

    cmbComboBox.Items.Clear();