Edit this page

Modes

RadTrackBar supports three different modes - SingleThumb, StartFromTheBeginning and Range. Each of these modes defines its own functionality and behavior. You can change the mode of the control via its TrackBarMode property.

SingleThumb

In this mode RadTrackBar works like a standard TrackBar. It contains one thumb and its value can be accessed through the Value property of RadTrackBar. To receive notification when value is changed you can use the ValueChanged event.

Figure 1:

track-and-status-controls-trackbar-modes 001

StartFromTheBeginning

In this mode RadTrackBar looks like RadTrackBar in SingleThumb mode, but it can contain more than one thumb. To show more than one thumb you should add the desired ranges (TrackBarRange) in the Ranges collection of control. For example:

this.radTrackBar1.TrackBarMode = Telerik.WinControls.UI.TrackBarRangeMode.StartFromTheBeginning;
this.radTrackBar1.Ranges.Add(new TrackBarRange(0, 5, "MyRange1"));
this.radTrackBar1.Ranges.Add(new TrackBarRange(0, 15, "MyRange2"));

Me.RadTrackBar1.TrackBarMode = Telerik.WinControls.UI.TrackBarRangeMode.StartFromTheBeginning
Me.RadTrackBar1.Ranges.Add(New TrackBarRange(0, 5, "MyRange1"))
Me.RadTrackBar1.Ranges.Add(New TrackBarRange(0, 15, "MyRange2"))

track-and-status-controls-trackbar-modes 002

In order to access the values of the thumbs in this mode you should go through the Ranges collection and check the values of each TrackBarRange. Please, note that even though TrackBarRange has both Start and End properties, in this mode RadTrackBar uses only the End property, so you should access it in order to take the value of some range.

float fitstRangeValue = this.radTrackBar1.Ranges[0].End;
float secondRangeValue = this.radTrackBar1.Ranges[1].End;

Dim fitstRangeValue As Single = Me.RadTrackBar1.Ranges(0).[End]
Dim secondRangeValue As Single = Me.RadTrackBar1.Ranges(1).[End]

To receive notification when the Value is changed in this mode, you should use the CollectionChanged event of the Ranges collection:

void Ranges_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
{
    if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.ItemChanged) 
    {
        foreach (object item in e.NewItems)
        {
            TrackBarRange range = item as TrackBarRange;
            if (range != null)
            {
                Console.WriteLine("Range {0} value {1}",range.Text, range.End);
            }
        }
    }
}

Private Sub Ranges_CollectionChanged(sender As Object, e As Telerik.WinControls.Data.NotifyCollectionChangedEventArgs)
    If e.Action = Telerik.WinControls.Data.NotifyCollectionChangedAction.ItemChanged Then
        For Each item As Object In e.NewItems
            Dim range As TrackBarRange = TryCast(item, TrackBarRange)
            If range IsNot Nothing Then
                Console.WriteLine("Range {0} value {1}", range.Text, range.[End])
            End If
        Next
    End If
End Sub

Range

This mode allows you to define one or more Ranges with Start and End values. In this mode there is a limitation that prevents the Ranges to overlap each other. To display a second range, you should add the desired Range (TrackBarRange) in the Ranges collection of the control. For example:

this.radTrackBar1.TrackBarMode = Telerik.WinControls.UI.TrackBarRangeMode.Range;
this.radTrackBar1.Ranges[0].Start = 2;
this.radTrackBar1.Ranges[0].End = 5;
this.radTrackBar1.Ranges.Add(new TrackBarRange(10, 15));

Me.RadTrackBar1.TrackBarMode = Telerik.WinControls.UI.TrackBarRangeMode.Range
Me.RadTrackBar1.Ranges(0).Start = 2
Me.RadTrackBar1.Ranges(0).[End] = 5
Me.RadTrackBar1.Ranges.Add(New TrackBarRange(10, 15))

track-and-status-controls-trackbar-modes 003

To receive notification when the Value is changed in this mode, you should use the CollectionChanged event of the Ranges collection:

void Ranges_CollectionChanged(object sender, Telerik.WinControls.Data.NotifyCollectionChangedEventArgs e)
{
    if (e.Action == Telerik.WinControls.Data.NotifyCollectionChangedAction.ItemChanged) 
    {
        foreach (object item in e.NewItems)
        {
            TrackBarRange range = item as TrackBarRange;
            if (range != null)
            {
                Console.WriteLine("Range {0} value {1}",range.Text, range.End);
            }
        }
    }
}

Private Sub Ranges_CollectionChanged(sender As Object, e As Telerik.WinControls.Data.NotifyCollectionChangedEventArgs)
    If e.Action = Telerik.WinControls.Data.NotifyCollectionChangedAction.ItemChanged Then
        For Each item As Object In e.NewItems
            Dim range As TrackBarRange = TryCast(item, TrackBarRange)
            If range IsNot Nothing Then
                Console.WriteLine("Range {0} value {1}", range.Text, range.[End])
            End If
        Next
    End If
End Sub

important

The Ranges collection of RadTrackBar contains one default range that is used to display a default range for all modes. This collection should always contain at least one range, so if you execute the Clear method of the collection all ranges except the first one will be removed.

note

When the mode is changed from StartFromTheBeginning to something else, the Radnges collection will be reset to prevent overlappings that are not allowed in the other modes.

See Also