New to Telerik UI for WPF? Download free 30-day trial

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

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" 
comboBoxItem = New RadComboBoxItem() 
comboBoxItem.Content = "Brickell Avenue" 

The result is shown on the image below:

WPF 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) 
End Sub 

See Also

In this article