--- title: Add and Remove Items from ComboBox, ListBox, or CheckedListBox Control ms.date: "03/30/2017" description: Learn how to add and remove a Windows Forms ComboBox, ListBox, and CheckedListBox controls simply and with no data binding. dev_langs: - "csharp" - "vb" - "cpp" helpviewer_keywords: - "combo boxes [Windows Forms], adding items" - "list boxes [Windows Forms], removing items" - "ComboBox control [Windows Forms], adding and removing items" - "ListBox control [Windows Forms], adding and removing items" - "list boxes [Windows Forms], adding items" - "combo boxes [Windows Forms], removing items" - "CheckedListBox control [Windows Forms], adding and removing items" ms.assetid: 7224c8d2-4118-443e-ae1e-d7c17d1e69ee --- # 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 `ToString` method. ### To add items 1. Add the string or object to the list by using the `Add` method of the `ObjectCollection` class. The collection is referenced using the `Items` property: ```vb ComboBox1.Items.Add("Tokyo") ``` ```csharp comboBox1.Items.Add("Tokyo"); ``` ```cpp comboBox1->Items->Add("Tokyo"); ``` - or - 2. Insert the string or object at the desired point in the list with the `Insert` method: ```vb CheckedListBox1.Items.Insert(0, "Copenhagen") ``` ```csharp checkedListBox1.Items.Insert(0, "Copenhagen"); ``` ```cpp checkedListBox1->Items->Insert(0, "Copenhagen"); ``` - or - 3. Assign an entire array to the `Items` collection: ```vb Dim ItemObject(9) As System.Object Dim i As Integer For i = 0 To 9 ItemObject(i) = "Item" & i Next i ListBox1.Items.AddRange(ItemObject) ``` ```csharp System.Object[] ItemObject = new System.Object[10]; for (int i = 0; i <= 9; i++) { ItemObject[i] = "Item" + i; } listBox1.Items.AddRange(ItemObject); ``` ```cpp Array^ ItemObject = gcnew Array(10); for (int i = 0; i <= 9; i++) { ItemObject[i] = String::Concat("Item", i.ToString()); } listBox1->Items->AddRange(ItemObject); ``` ### To remove an item 1. Call the `Remove` or `RemoveAt` method to delete items. `Remove` has one argument that specifies the item to remove.`RemoveAt` removes the item with the specified index number. ```vb ' To remove item with index 0: ComboBox1.Items.RemoveAt(0) ' To remove currently selected item: ComboBox1.Items.Remove(ComboBox1.SelectedItem) ' To remove "Tokyo" item: ComboBox1.Items.Remove("Tokyo") ``` ```csharp // To remove item with index 0: comboBox1.Items.RemoveAt(0); // To remove currently selected item: comboBox1.Items.Remove(comboBox1.SelectedItem); // To remove "Tokyo" item: comboBox1.Items.Remove("Tokyo"); ``` ```cpp // To remove item with index 0: comboBox1->Items->RemoveAt(0); // To remove currently selected item: comboBox1->Items->Remove(comboBox1->SelectedItem); // To remove "Tokyo" item: comboBox1->Items->Remove("Tokyo"); ``` ### To remove all items 1. Call the `Clear` method to remove all items from the collection: ```vb ListBox1.Items.Clear() ``` ```csharp listBox1.Items.Clear(); ``` ```cpp listBox1->Items->Clear(); ``` ## See also - - - - [How to: Sort the Contents of a Windows Forms ComboBox, ListBox, or CheckedListBox Control](sort-the-contents-of-a-wf-combobox-listbox-or-checkedlistbox-control.md) - [When to Use a Windows Forms ComboBox Instead of a ListBox](when-to-use-a-windows-forms-combobox-instead-of-a-listbox.md) - [Windows Forms Controls Used to List Options](windows-forms-controls-used-to-list-options.md)