ComponentOne Input for WinForms
Removing Items from C1ComboBox
Using the C1Input Controls > C1Input Controls > C1ComboBox Control Overview > Removing Items from C1ComboBox

All Items or specific items can easily be removed from the C1ComboBox programmatically or at design time through the Strings Collection Editor.

Removing All Items Programatically

To programatically remove all items from C1ComboBox, complete the following:

To write code in Visual Basic

Visual Basic
Copy Code
c1ComboBox1.Items.Clear()

To write code in C#

C#
Copy Code
c1ComboBox1.Items.Clear();

 

Removing an Item Programatically

To programatically remove an item use the Remove or RemoveAt methods. The Remove method removes the specified item or selected item. The RemoveAt method removes the item with the specified index number.

The following code shows how to use the Remove and RemoveAt methods to remove specific items or remove selected items:

To write code in Visual Basic

Visual Basic
Copy Code
' To remove item with index 0:
c1ComboBox1.Items.RemoveAt(0)
' To remove currently selected item:
c1ComboBox1.Items.Remove(ComboBox1.SelectedItem)
' To remove "Chicago" item:
c1ComboBox1.Items.Remove("Chicago")

To write code in C#

C#
Copy Code
// To remove item with index 0:
comboBox1.Items.RemoveAt(0);
// To remove currently selected item:
comboBox1.Items.Remove(comboBox1.SelectedItem);
// To remove "Chicago" item:
comboBox1.Items.Remove("Chicago");
See Also