We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How sync the order of the itemssource-collection with the view

Thread ID:





140723 Nov 3,2018 07:05 PM UTC Nov 7,2018 03:11 AM UTC WPF 3
Tags: SfTreeGrid
Asked On November 3, 2018 09:26 PM UTC


I am trying to work with the SfThreeGrid. Which is really a great control.

For the itemsource I use an ObservableCollection<>.

While drag-and-dropping the items to restructure them, I notice that items are not restructured in the ObservableCollection.

How do I accomplish a full sync of the order/structure of the itemssource and the view?

Basically I need the node-order to be reflected back into the itemssource collection.

Please advise.

Best regards,

Deivaselvan Y [Syncfusion]
Replied On November 5, 2018 06:42 PM UTC

Hi Johannes,

Thank you for contacting Syncfusion support.

We have analyzed your query “To reorder itemsSource collection based on the visual order after drag and drop” and you can achieve your requirement by handling RowDragDropController.Dropped event as like below code snippet 


AssociatedObject.RowDragDropController.Dropped += sfGrid_Dropped; 


private void sfGrid_Dropped(object sender, TreeGridRowDroppedEventArgs e)


    if (e.DropPosition != DropPosition.None)


        //Get Dragging nodes

        ObservableCollection<TreeNode> draggingRecords = e.Data.GetData("Nodes") as ObservableCollection<TreeNode>;

        if (draggingRecords == null)


        ViewModel model = AssociatedObject.DataContext as ViewModel;

        //Use Batch update to avoid data operations in SfTreeGrid during records removing and inserting


        //Removes the dragging nodes from the underlying collection

        foreach (TreeNode item in draggingRecords)


            model.Employees.Remove(item.Item as EmployeeInfo);


        //Find the target node index after removing the nodes

        int targetIndex = model.Employees.IndexOf(e.TargetNode.Item as EmployeeInfo);

        int insertionIndex = e.DropPosition == DropPosition.DropAbove ? targetIndex : targetIndex + 1;

        insertionIndex = insertionIndex < 0 ? 0 : insertionIndex;

        //Insert dragging nodes to the target position

        for (int i = draggingRecords.Count - 1; i >= 0; i--)


            model.Employees.Insert(insertionIndex, draggingRecords[i].Item as EmployeeInfo);






Please find sample for the same from below link and let us know if this helps you. 




Replied On November 5, 2018 09:15 PM UTC


Thank you for this. I will try it out soon.

However, does this not presume the list to be sorted correctly as a starting point?

The data in itemssource might not sorted directly as visualized. I.e. two root-level nodes cn be at the beginning while the child-nodes add up in different order afterwards. This would still be visualized correct, but the itemssource would not updated to reflect to visual order. Also the drag-and-drop solution might not bring the full visual order to the itemssource, but also place the dragged-and-dropped items to the correct position in itemssource. Correct?

Would it be possible to somehow make dump of full nodes list, get the item and use it to reorder the itemssource?

Best regards,

Deivaselvan Y [Syncfusion]
Replied On November 7, 2018 03:11 AM UTC

Hi Johannes,

This given solution will update ItemsSource collection with same order of dropping nodes and it doesn’t update the ItemsSource with the sorting order. You can get the Sorting order of the Collection from SfTreeGrid.View.Records.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon