Edit this page

In Code-Behind

This tutorial will walk you through the common tasks of adding and removing RadComboBoxItems programmatically.

Here is a regular RadComboBox declaration without items:

XAML

<telerik:RadComboBox x:Name="radComboBox" Width="200">
</telerik:RadComboBox>

Adding RadComboBoxItems

In order to add new combo box items to a RadComboBox control, you have to perform several simple steps:

  • Create an instance of the RadComboBoxItem class.

  • Set its properties such as Content, Foreground, etc.

  • Add it to the RadComboBox's Items collection.

C#

RadComboBoxItem comboBoxItem = new RadComboBoxItem();
comboBoxItem.Content = "Alapattah";
this.radComboBox.Items.Add( comboBoxItem );

comboBoxItem = new RadComboBoxItem();
comboBoxItem.Content = "Brickell Avenue";
this.radComboBox.Items.Add( comboBoxItem );

VB.NET

Dim comboBoxItem As New RadComboBoxItem()
comboBoxItem.Content = "Alapattah"
Me.radComboBox.Items.Add(comboBoxItem)

comboBoxItem = New RadComboBoxItem()
comboBoxItem.Content = "Brickell Avenue"
Me.radComboBox.Items.Add(comboBoxItem)

The result is shown on the image below:

Consider declaring combo box items in XAML instead of adding them by code whenever it's possible. This includes situations when you know what items you need at design time.

Removing RadComboBoxItems

In order to remove a specific RadComboBoxItem, you should remove it from the RadComboBox's Items collection.

C#

private void RemoveComboBoxItem( RadComboBoxItem itemToRemove )
{
    this.radComboBox.Items.Remove( itemToRemove );
}

VB.NET

Private Sub RemoveComboBoxItem(ByVal itemToRemove As RadComboBoxItem)
    Me.radComboBox.Items.Remove(itemToRemove)
End Sub

See Also