Edit this page

Selection

RadTabControl exposes several useful properties and events, which can help you to work with items selections.

Properties

  • By using SelectedIndex property you can get or set the index of the currently selected tab item.

  • By using SelectedItem property you can get or set the currently selected tab item. The reference you are passing should be to an instance of RadTabItem that has already been added to the tab control items collection.

If your tab control is bound to a custom collection, then the property SelectedItem will not return RadTabItem as you might expect, but item of the type the source collection contains i.e. Person, TabModel etc.

  • Another way to make certain tab item selected is by using the RadTabItem’s property IsSelected. This is a Boolean property and when set to True, that specific tab item is selected, while the previous one gets deselected.

  • Use the SelectedContent property to get or set the content of the currently selected tab item. Please note that, when you set value to this property you will replace the content of the currently selected tab item, but the selected tab item will not change, it will stay the same.

The items counting is zero based, meaning that the index of the first tab items is 0, the index of the second item is 1 and so on. Make sure you set the If you want to clear the selection just set the property SelectedIndex to -1.

<telerik:RadTabControl x:Name="radTabControl" SelectedIndex="1" SelectionChanged="radTabControl_SelectionChanged">
</telerik:RadTabControl>

The implementation of the event handler radTabControl_SelectionChanged is located in the code-behind file (C# or VB.NET) and looks like this:

private void radTabControl_SelectionChanged( System.Object sender, System.Windows.RoutedEventArgs e )
{
    RadSelectionChangedEventArgs selectionArgs = ( RadSelectionChangedEventArgs )e;
    MessageBox.Show( “The selected tab item is ” + ( ( RadTabItem )selectionArgs.AddedItems[ 0 ] ).Header.ToString() );
}
Private Sub radTabControl_SelectionChanged( ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        Dim selectionArgs As RadSelectionChangedEventArgs = DirectCast(e,RadSelectionChangedEventArgs)
        MessageBox.Show("The selected tab item is " + DirectCast(selectionArgs.AddedItems(0), RadTabItem).Header.ToString() )
End Sub

If your tab control is bound to a custom collection, the code above will fail with InvalidCastException, because the AddedItems collection will no longer contain items of type RadTabItem and the explicit cast will fail. The collection will contain items that are of the same type that the source collection contains i.e. Person, TabModel etc.

See Also