Edit this page

In Code Behind

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

Here is a regular RadListBox declaration without items:

Declaring RadListBox

<telerik:RadListBox x:Name="radListBox" Width="200">            
</telerik:RadListBox>

Adding RadListBoxItems

In order to add new listbox items to a RadListBox control, you have to perform several simple steps:

  • Create an instance of the RadListBoxItem class.

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

  • Add it to the RadListBox's Items collection.

Populating RadListBox with items from code-behind

var item1 = new RadListBoxItem() { Content = "Australia" };
radListBox.Items.Add(item1);
var item2 = new RadListBoxItem() { Content = "Brazil" };
radListBox.Items.Add(item2);

The result is shown on the image below:

radlistbox populatingwithdata incodebehind

Removing RadListBoxItems

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

Removing RadListBoxItems

private void RemoveListBoxItem(RadListBoxItem itemToRemove)
{
    this.radListBox.Items.Remove(itemToRemove);
}

See Also