Multi Select in SfListView

Hello,

Can I implement multi-select in the sFListview control?
Add a checkbox to the data item template, then get all checked items once done?

If so, a sample would be great, thanks!

7 Replies

MK Muthu Kumaran Gnanavinayagam Syncfusion Team February 9, 2018 12:11 PM UTC

Hi Lindsay, 
 
Thank you for contacting Syncfusion support. 
 
We have checked your requirement “Need to get all the checked items of CheckBox inside the ItemTemplate of SfListView” from our side. We would like to inform you that the SfListView provides support for selecting Multiple items by setting the SelectionMode property value as ‘Multiple’. You can refer the below link for details about selection in SflistView. 
 
 
Currently, Xamarin.Forms does not have a separate CheckBox element. However you can achieve your requirement through an workaround by loading checked and unchecked images inside the ItemTemplate of SfListView and while performing selection, you can change those image sources accordingly. You can get the collection of items which are selected in the SelectedItems property of SfListView and you can display those items in Entry or Label element as per your requirement.  
 
For your assistance, we have attached the sample and you can download it from the below location. 
 
 
In our sample, you can tap the ‘Arrow’ button next to the Grid area to display the SfListView in a PopUpView. Then you can select any number of list items to display them in the Label loaded inside the Grid area. 
 
Please let us know if you require further assistance. 
 
Regards, 
G.Muthu kumaran. 



LM Lindsay Miles February 11, 2018 08:43 PM UTC

Thanks, I will try implement that and see if it works for us.

At some point, it might be a good idea to add an Index property to Listview items. That would make handling itemselected event a little easier (e.SelectedItem.Index  OR an Index property to the ItemTappedEventArgs) and not have to always deal with the SelectedItem object itself. This would be good for single selection where a ListView is used for something like menuItems etc etc. 

Thanks again


MK Muthu Kumaran Gnanavinayagam Syncfusion Team February 12, 2018 12:48 PM UTC

Hi Lindsay, 
 
We have checked the reported query “Need to get the Index of the selected item” from our side. We would like to let you know that you can get the selected item index by passing the underlying data in DisplayItems.IndexOf method as like below code example. 
 
Code example[C#]: 
private void listView_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)  
  {  
    if (e.PropertyName == "SelectedItem" && listView != null)  
      var selectedItemIndex = listView.DataSource.DisplayItems.IndexOf(listView.SelectedItem);  
  }  
 
 
Please let us know if you require further assistance. 
 
Regards, 
G.Muthu kumaran. 



LM Lindsay Miles February 12, 2018 02:13 PM UTC

Ah ha! Thank you! That makes working with this so much easier!


MK Muthu Kumaran Gnanavinayagam Syncfusion Team February 13, 2018 04:38 AM UTC

Hi Lindsay, 
 
Thanks for your valuable response. 
 
Regards, 
G.Muthu kumaran. 



SW SHREYANS WAKEKAR replied to Muthu Kumaran Gnanavinayagam June 13, 2018 10:50 AM UTC

Hi Lindsay, 
 
Thanks for your valuable response. 
 
Regards, 
G.Muthu kumaran. 


What is PopUpView in the example provided ?


MK Muthu Kumaran Gnanavinayagam Syncfusion Team June 14, 2018 10:25 AM UTC

Hi Shreyans, 
 
In our sample, the PopUpView is just a custom ContentView used to display the SfListView as like multi selection drop down list. 
 
Regards, 
G.Muthu kumaran. 


Loader.
Up arrow icon