How to: Add and Remove Items from a Windows Forms ComboBox, ListBox, or CheckedListBox Control
Items can be added to a Windows Forms combo box, list box, or checked list box in a variety of ways, because these controls can be bound to a variety of data sources. However, this topic demonstrates the simplest method and requires no data binding. The items displayed are usually strings; however, any object can be used. The text that is displayed in the control is the value returned by the object's
Add the string or object to the list by using the
Addmethod of the
ObjectCollectionclass. The collection is referenced using the
- or -
Insert the string or object at the desired point in the list with the
- or -
Assign an entire array to the
RemoveAtmethod to delete items.
Removehas one argument that specifies the item to remove.
RemoveAtremoves the item with the specified index number.
Clearmethod to remove all items from the collection:
How to: Sort the Contents of a Windows Forms ComboBox, ListBox, or CheckedListBox Control
When to Use a Windows Forms ComboBox Instead of a ListBox
Windows Forms Controls Used to List Options