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:

<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.

RadComboBoxItem comboBoxItem = new RadComboBoxItem(); 
comboBoxItem.Content = "Alapattah"; 
this.radComboBox.Items.Add( comboBoxItem ); 
 
comboBoxItem = new RadComboBoxItem(); 
comboBoxItem.Content = "Brickell Avenue"; 
this.radComboBox.Items.Add( comboBoxItem ); 
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:

Silverlight RadComboBox with Items Defined in Code-Behind

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.

private void RemoveComboBoxItem( RadComboBoxItem itemToRemove ) 
{ 
    this.radComboBox.Items.Remove( itemToRemove ); 
} 
Private Sub RemoveComboBoxItem(ByVal itemToRemove As RadComboBoxItem) 
    Me.radComboBox.Items.Remove(itemToRemove) 
End Sub 

See Also

In this article