Restrict the number of selected items

Hi,

Is it possible to restrict the number of selected items? For example i have a ListView with 10 items and 
i just want to let 3 items can be selected. If user want to select 4th one, first of all user will deselect
one item (inform the user with alerts) and choose what his/her want to choose as third one again.
But the total number of items selected will always remain 3

1 Reply

JN Jayaleshwari N Syncfusion Team September 24, 2018 09:17 AM UTC

Hi Pinar,  
  
Thanks for using Syncfusion products.  
  
We have checked the reported query “Restrict the number of selected items” from our end. We would like to let you know that you can achieve your requirement by handling the selection in the SelectionChanging event of SfListView like below code snippet.  
  
Code Example[C#]:  
public partial class GroupingPage : ContentPage  
    {  
        public GroupingPage()  
        {  
            InitializeComponent();  
            listView.SelectionChanging += ListView_SelectionChanging;  
        }  
  
        private void ListView_SelectionChanging(object sender, Syncfusion.ListView.XForms.ItemSelectionChangingEventArgs e)  
        {  
            var addeditem = e.AddedItems.Count;  
            if (listView.SelectedItems.Count >= 3 && addeditem != 0)  
            {  
                e.Cancel = true;  
                DisplayAlert("", "You can select only 3 items.Can you please deselect any one item", "OK");  
            }  
        }  
    }  
  
For your reference we have attached the sample and you can download it from the below link.  
  
  
Please let us know if you require further assistance on this.  
  
Regards,  
Jayaleshwari N 


Loader.
Up arrow icon