- Home
- Forum
- Xamarin.Forms
- Drag/Drop - save and resequence underlying datasource at the end
Drag/Drop - save and resequence underlying datasource at the end
In my app, I want the user to be able to resequence all of the listview items and then tap "Save" at the end to confirm all is ok before touching the datasource.
I have checked out this article, but it doesn't do what I want. It updates the underlying data source with each drag/drop. I want to do this at the end in bulk. https://www.syncfusion.com/forums/154831/saving-re-order-items-in-listview-which-have-grouping-enable
After tapping a Save button, I want to:
1. Loop through the listview items as shown in the new sequence
2. Perform the move on the underlying datasource
How can I loop through the listview items in the new re-ordered sequence as shown, with a link to the underlying datasource for each item so I can update those records?
Thanks
SIGN IN To post a reply.
3 Replies
1 reply marked as answer
LN
Lakshmi Natarajan
Syncfusion Team
November 12, 2020 03:53 AM UTC
Hi Joseph,
Thank you for using Syncfusion products.
We have checked the reported query “Drag/Drop - save and resequence underlying datasource at the end” from our side. We would like to inform you that you can get the reordered items from the ListView.DataSource.DisplayItems. Please refer the following code snippets to achieve your requirement,
In the SaveButton.Clicked event, get the reordered list from the DataSource.DisplayItems and set it to the underlying ViewModel collection.
|
public class Behavior : Behavior<ContentPage>
{
SfListView ListView;
Button SaveButton;
protected override void OnAttachedTo(ContentPage bindable)
{
ListView = bindable.FindByName<SfListView>("ToDoListView");
SaveButton = bindable.FindByName<Button>("saveButton");
SaveButton.Clicked += SaveButton_Clicked;
base.OnAttachedTo(bindable);
}
private void SaveButton_Clicked(object sender, EventArgs e)
{
var newList = new List<ToDoItem>();
foreach (var item in ListView.DataSource.DisplayItems)
{
newList.Add((ToDoItem)item);
}
(ListView.BindingContext as ViewModel).ToDoList = new ObservableCollection<ToDoItem>(newList);
}
} |
We have prepared a sample based on your requirement and you can download it from the following link,
Please let us know if you need further assistance.
Regards,
Lakshmi Natarajan
Marked as answer
JH
Joseph Hanna
November 12, 2020 11:57 AM UTC
Thanks Lakshmi! That is perfect
LN
Lakshmi Natarajan
Syncfusion Team
November 12, 2020 03:01 PM UTC
Hi Joseph,
Thank you for the update.
We are glad that our solution meets your requirement. Please let us know if you need any further update. As always we are happy to help you out.
Lakshmi Natarajan
SIGN IN To post a reply.
- 3 Replies
- 2 Participants
- Marked answer
-
JH Joseph Hanna
- Nov 10, 2020 07:14 AM UTC
- Nov 12, 2020 03:01 PM UTC