Dragging and dropping items in SFListView does not change underlying collection

The underlying collection "lstEquation.DataSource" does not change when I drag and drop the order of items within SFListView. I have used UpdateSource=True.Not sure if I am using it right, though.


Here's my xaml code:

UpdateSource="True">


Here's my .cs code:


private void LstEquation_ItemDragging(object sender, Syncfusion.ListView.XForms.ItemDraggingEventArgs e)

{

if (e.Action == Syncfusion.ListView.XForms.DragAction.Drop)

{

for (int i = 0; i < EquationComponents.Count; i++)

EquationComponents[i] = lstEquation.DataSource.Items[i]; //DataSource does not change at all //even after reordering through drag //and drop


}

}


Any help would be appreciated.  Thanks.


1 Reply

LN Lakshmi Natarajan Syncfusion Team June 30, 2021 01:51 PM UTC

Hi Sree, 
 
Thank you for using Syncfusion products. 
 
We have checked the reported query “Dragging and dropping items in SFListView does not change underlying collection” from our side. We would like to inform you that the SfListView will automatically update the underlying collection by using the SfListView.DragDropController.UpdateSource as True. Also, in the ItemDragging event, you can get the updated list from the MainThread since the UI changes will be updated in the MainThread in Xamarin.Forms.    
 
Please refer to our user guidance document from the following link, 
 
Please refer to the following code snippets for more reference, 
 
XAML 
<syncfusion:SfListView x:Name="ToDoListView" ItemSize="60" IsStickyHeader="True" ItemsSource="{Binding ToDoList}" DragStartMode="OnHold,OnDragIndicator" SelectionMode="None"> 
        <syncfusion:SfListView.DragDropController> 
            <syncfusion:DragDropController UpdateSource="True"/> 
        </syncfusion:SfListView.DragDropController> 
 
In the drop action, you can get the reordered items from the underlying collection or SfListView.DataSource.DisplayItems. 
private void ListView_ItemDragging(object sender, ItemDraggingEventArgs e) 
{ 
    if (e.Action == DragAction.Drop) 
    { 
        Device.BeginInvokeOnMainThread(() => 
        { 
            var items = (ListView.BindingContext as ViewModel).ToDoList; 
        }); 
    } 
} 
 
You can also refer to our online documentation to update underlying collection manually from the following link, 
 
Please let us know if you need further assistance. 
 
Lakshmi Natarajan 
 


Loader.
Up arrow icon