Selection

The RadListView component exposes selection feature. It allows users to select one or many items out of the ItemsSource of the control. This feature provides both visual and programmatic feedback for the actions of the user. The following members are related to the selection:

  • SelectionGesture (SelectionGesture): Gets or sets the gesture triggering the selection.
    • Tap
    • Hold
  • SelectionMode (SelectionMode): Gets or sets the mode of the selection.

    • None - This mode doesn't allow users to select an item. To enable it the SelectionMode property should be set to None.
    • Single - This is the default selection mode. It allows users to select only one item.
    • Multiple - This mode allows users to select more than one item. To enable it the SelectionMode property should be set to SelectionMode.Multiple.
  • SelectedItems (ObservableCollection<object>): Gets or sets the currently selected items.

  • SelectedItem (object): Gets the last selected item.
  • SelectionChanged: An event that is triggered whenever the SelectedItems collection is changed.

Example

Here is the definition of the ListView control:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition/>
    </Grid.RowDefinitions>

    <StackLayout Padding="10">
        <Label Text="Set selection mode:" FontSize="Medium"/>
        <Picker x:Name="selectionModePicker" AutomationId="SelectionModePicker"/>
        <Label Text="Set selection gesture:" FontSize="Medium"/>
        <Picker x:Name="selectionGesturePicker" AutomationId="SelectionGesturePicker"/>
    </StackLayout>

    <telerikDataControls:RadListView  x:Name="listView" Grid.Row="1">
        <telerikDataControls:RadListView.SelectedItemStyle>
            <telerikListView:ListViewItemStyle BackgroundColor="#88888888"/>
        </telerikDataControls:RadListView.SelectedItemStyle>
    </telerikDataControls:RadListView>
</Grid>

and lets create a simple data for the ListView component and a method called InitializePickers in which we can add the modes and gestures we want to use:

public Selection()
{
    this.InitializeComponent();
    listView.ItemsSource = new List<string> { "Tom", "Anna", "Peter", "Teodor", "Lorenzo", "Andrea", "Martin" };
    this.InitializePickers();
}

private void InitializePickers()
{
    selectionModePicker.Items.Add("None");
    selectionModePicker.Items.Add("Single");
    selectionModePicker.Items.Add("Multiple");
    selectionModePicker.SelectedIndexChanged += this.OnSelectionModeChanged;
    selectionModePicker.SelectedIndex = 1;

    selectionGesturePicker.Items.Add("Tap");
    selectionGesturePicker.Items.Add("Hold");
    selectionGesturePicker.SelectedIndexChanged += this.OnSelectionGestureChanged;
    selectionGesturePicker.SelectedIndex = 0;
}

We can control the behavior of the RadListView's selection when changing the selection of the Pickers. The methods that are related with the Picker functionality are OnSelectionGestureChanged and OnSelectionModeChanged. We use them to change the SelectionGesture/SelectionMode of the RadListView.

Here is an example how those methods can be implemented:

private void OnSelectionGestureChanged(object sender, EventArgs e)
{
    switch ((sender as Picker).SelectedIndex)
    {
        case 0:
            listView.SelectionGesture = SelectionGesture.Tap;
            break;
        case 1:
            listView.SelectionGesture = SelectionGesture.Hold;
            break;
    }
}

private void OnSelectionModeChanged(object sender, EventArgs e)
{
    switch ((sender as Picker).SelectedIndex)
    {
        case 0:
            listView.SelectionMode = SelectionMode.None;
            break;
        case 1:
            listView.SelectionMode = SelectionMode.Single;
            break;
        case 2:
            listView.SelectionMode = SelectionMode.Multiple;
            break;
    }
}

Single Selection

This is how the RadListView control will look like when the single selection mode is set.

SingleSelection

Multiple Selection

Here is how the RadListView control will look like when the multiple selection mode is set.

MultipleSelection

SDK Browser application contains an example that shows Selection feature in RadListView cotrol. You can find the application in the Examples folder of your local Telerik UI for Xamarin installation.

See Also

Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy