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. Image for the cookie policy date

SfDataGrid Loses sort order when an element is added to its binded collection


I have 2 Grids [SfDataGrid]. User clicks some Add button to add record(s) from one grid to another.  The grids are bound to two collections. The target grid is already sorted on an ID column. When a record is added to the target grid, the target grid loses the sort order, i.e. the newly added record does get inserted in the right place. 
In order to retain the sort order on the target grid after a record is added, I have written an event handler on the View object of the target grid [DataGrid.View.SourceCollectionChanged += View_SourceCollectionChanged]. In this event handler, I clear the SortColumnDescriptions collection and re add the Sort Item again. 

SortColumnDescription sortItem = new SortColumnDescription();
sortItem.ColumnName = ColumnName;
sortItem.SortDirection = System.ComponentModel.ListSortDirection.Ascending;;

The above code sorts the records on the target grid after a new record is added to its ItemSource ollection. But the problem is, the last added record always appears twice on the target grid. Even if I add multiple records, its only the last added record which appears twice and rest of the records are displayed in the proper sort order.
In the debugger, I checked the Records collection of the View object on the target grid, the DataGrid.View.Records shows the records properly [in the proper sort order], i.e. it does not show any record twice. I am baffled where does this extra record come from? 

Am I missing any IsSynchronizedWithCurrentItem kind of property?

Any suggestion?

Soumyajit Roy

9 Replies

AR Akila Rajaram Syncfusion Team June 5, 2015 12:47 PM UTC

Hi Soumyajit ,

Thank you for using Syncfusion Products.

You can directly  apply sorting for newly added record in button click by setting LiveDataUpdateMode as AllowDataShapping and there is no need to use the SourceCollectionChanged event which is specified in your  update  .We have prepared the sample based on your requirement . Please find the sample from the following location ,

Sample : http://www.syncfusion.com/downloads/support/forum/119324/ze/SfDataGrid_Sample_119324222495554

Please refer the following code example :


<syncfusion:SfDataGrid x:Name="grid"





                               ItemsSource="{Binding Stud}"


Please refer the below ug link for more information about data manipulation in SfDataGrid,

Link : http://help.syncfusion.com/ug/wpf/index.html#!Documents/datamanipulation.htm

Please let us know if you require further assistance on this .

Akila R.

SR Soumyajit Roy June 5, 2015 03:57 PM UTC

Thank You Akila. The solution is so effective, lot less code and clean.

SC Saranya CJ Syncfusion Team June 8, 2015 05:30 AM UTC

Hi Soumyajit,

Thank you for your update. Please let us know if you require any other assistance.


XU xudongli September 28, 2017 01:13 PM UTC

this doesn't work for me when I have customised sorting class

MK Muthukumar Kalyanasundaram Syncfusion Team October 1, 2017 03:56 AM UTC

Hi Xudongli, 

Thank you for your update. 

We are unable to reproduce the reported “Custom sorting is not worked properly while adding item in grid” issue in our end. Could you please share your xaml and customized sorting class files along with the model details if you did any other customization in grid?.  We could analyze further and resolve your reported issue at the earliest. 
Muthukumar K 

DA Dumitriu Ana-Florentina April 28, 2020 04:37 PM UTC

I have the same problem as the initiator above, but I have Unbound columns which don't allow me to use LiveDataUpdateMode as AllowDataShapping.
How can I solve it?

VS Vijayarasan Sivanandham Syncfusion Team April 29, 2020 03:54 PM UTC

Hi Dumitriu Ana-Florentina,

Thank you for contacting Syncfusion support.

We have checked the reported issue and unable to replicate the issue from our end. Please find the tested sample and video demo from our end in the below link,
if you still facing the same issue? If yes, please modify the sample based on your scenario.  
It will be helpful for us to check on it and provide you the solution at the earliest.     
Vijayarasan S

DA Dumitriu Ana-Florentina April 30, 2020 08:00 AM UTC

Hello, thank you for your help!
We tried this solution once, but it seemed it was another configuration that affected AllowDataShapping.
It works now.

Have a nice day!

MA Mohanram Anbukkarasu Syncfusion Team May 1, 2020 09:50 AM UTC

Hi Dumitriu, 

Thanks for the update. 

We are glad to know that the reported problem has been resolved at your end. Please let us know if you have any further queries on this. We are happy to help you. 

Mohanram A. 

Live Chat Icon For mobile
Up arrow icon