How to skip a selection for any specific index or based on selected items count in xamarin.forms listview?
In Xamarin.Forms ListView, you can skip selection for any specific item index based on the selected items count using AddedItems in the SelectionChangingEvent.
XAML
<ContentPage xmlns:syncfusion="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms" >
<ContentPage.Content>
<Grid >
<syncfusion:SfListView x:Name="listView" ItemsSource="{Binding contactsinfo}" SelectionChanging="listView_SelectionChanging" SelectionMode="Multiple">
</syncfusion:SfListView>
</Grid>
</ContentPage.Content>
</ContentPage>
C#
namespace ListViewSample
{
public partial class ListViewSample : ContentPage
{
private void listView_SelectionChanging(object sender, Syncfusion.ListView.XForms.ItemSelectionChangingEventArgs e)
{
var addedItemCount = e.AddedItems.Count;
if (addedItemCount == 0)
return;
var items = e.AddedItems;
var index = listView.DataSource.DisplayItems.IndexOf(items[0]);
if (index == 0)
e.Cancel = true; //Selection cancelled for 1st item
if (listView.SelectedItems.Count>=3 && addedItemCount != 0)
{
e.Cancel = true;
DisplayAlert("Message", "You can select only 3 items.Can you please deselect any one item", "Ok");
}
}
}
}
Screenshot:

Sample link: Skip selection in ListView