Hi,
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.
SortColumnDescriptions.Clear();
SortColumnDescription sortItem = new SortColumnDescription();
sortItem.ColumnName = ColumnName;
sortItem.SortDirection = System.ComponentModel.ListSortDirection.Ascending;;
SortColumnDescriptions.Add(sortItem);
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?
Thanks,
Soumyajit Roy