Swiping: Listview uses wrong itemIndex value when it is grouped

I implemented the swiping gesture to a listview control, based on the sample code found here:

https://help.syncfusion.com/xamarin/listview/swiping#working-with-multiple-views-in-swipe-template


My list is grouped by department. When I swipe to perform an action, the itemIndex property is wrong. If the list isn’t grouped, the itemIndex for the selected item on the list is correct. Also, if the listview is grouped and I swipe the last item, the app throws an index exception and crashes.


How can I correct this issue?


Thanks in advance for your help. 


Andres


3 Replies 1 reply marked as answer

LN Lakshmi Natarajan Syncfusion Team April 28, 2021 11:13 AM UTC

Hi Andres,

Thank you for using Syncfusion products.
 
 
We have checked the reported query “Listview uses wrong ItemIndex value when it is grouped”. We would like to let you know that the ItemIndex does not represent the index of the item in the ItemsSource collection, it represents the index of display items of SfListView. Hence, you can achieve your requirement by using ItemData which you can get in SwipeEndedEventArgs instead of ItemIndex.   
  
   
Please refer the following code example for the same, 
private void ListView_SwipeEnded(object sender, Syncfusion.ListView.XForms.SwipeEndedEventArgs e) 
{ 
    var data = e.ItemData as Contacts; 
    var items = (ListView.BindingContext as ContactsViewModel).ContactsInfo; 
    var _index = items.IndexOf(items.FirstOrDefault(itemData => itemData == data)); 
    App.Current.MainPage.DisplayAlert("Swiped item index", _index.ToString(), "Ok"); 
} 
 
 
We have attached the sample in the following link, 
 
#Regarding  I swipe the last item, the app throws an index exception and crashes 
 
We would like to inform you that we are unable to reproduce the reported issue at our side. Please check our sample and let us know if you still facing the same issue? if not, please modify our sample to reproduce the issue which will be helpful for us to check further and provide you the solution as soon as possible. 
 
Please let us know if you need further assistance. 
 
Regards, 
Lakshmi Natarajan 
 


Marked as answer

AA Andres Alvarado April 28, 2021 09:38 PM UTC

Hi Lakshmi! Thanks for your response. Based on your sample, I was able to get the list to work as expected. I really appreciate it :D

Andres.


LN Lakshmi Natarajan Syncfusion Team April 29, 2021 04:20 AM UTC

Hi Andres, 
 
Thank you for the update. 
 
We are glad that our solution meets your requirement. Please let us know if you need further assistance. As always we are happy to help you out. 
 
Lakshmi Natarajan 
 


Loader.
Up arrow icon