Edit this page

In Code-Behind

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

Here is a regular RadRating declaration:

<telerik:RadRating x:Name="radRating"/>

Adding RadRatingItems

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

  • Create an instance of the RadRatingItem class

  • Set its properties such as Content if you need so

  • Add it to the RadRating's Items collection

        RadRatingItem ratingItem = new RadRatingItem();
        this.radRating.Items.Add(ratingItem);
    
        Dim ratingItem As New RadRatingItem()
        Me.radRating.Items.Add(ratingItem)
    

The result is shown on the image below:

In order to clear the default rating items and add new you have to add one additional step to the previous:

  • Clear the Items collection of the RadRating control

  • Create an instance of the RadRatingItem class

  • Set its properties such as Content if you need so

  • Add it to the RadRating's Items collection

this.radRating.Items.Clear(); 
RadRatingItem ratingItem = new RadRatingItem();
ratingItem.Content = "1";
this.radRating.Items.Add(ratingItem);
ratingItem = new RadRatingItem();
ratingItem.Content = "2";
this.radRating.Items.Add(ratingItem);
Me.radRating.Items.Clear() 
Dim ratingItem As New RadRatingItem()
ratingItem.Content = "1"
Me.radRating.Items.Add(ratingItem)
ratingItem As New RadRatingItem()
ratingItem.Content = "2"
Me.radRating.Items.Add(ratingItem)

The result is shown on the image below:

Consider declaring rating 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 RadRatingItems

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

private void RemoveRatingItem( RadRatingItem itemToRemove )
{
   this.radRating.Items.Remove( itemToRemove );
}
Private Sub RemoveRatingItem(ByVal itemToRemove As RadRatingItem)
    Me.radRating.Items.Remove(itemToRemove)
End Sub
Was this article helpful? Yes No

Give article feedback

Tell us how we can improve this article

Dummy