This is a migrated thread and some comments may be shown as answers.

Automatic sorting event when cell is edited

1 Answer 166 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Procurement
Top achievements
Rank 1
Procurement asked on 28 Jan 2013, 01:42 PM
Hi, 


I'm struggling on a sorting problem. I have 2 gridviews that are bound to the same list. Only one of the gridviews is editable. The other one is for reporting purposes only and so readonly. 

Because they represent the same data, the filtering and sorting must be syncronized. For the sorting part, I've added a 'Sorting' event on grid n°1. In the event handler I copy the sorting descriptors into the second grid. This works fine.

private void GridViewSorted(object sender, GridViewSortedEventArgs e)
{
    var datagrid = sender as RadGridView;
    if (datagrid == null || !datagrid.Equals(EmployeeGrid)) return;
 
    FormationGrid.SortDescriptors.Replace(datagrid.SortDescriptors);
}


When I edit a cell of one of the sorted columns in grid n°1, the grid is automatically sorted according to the existing sorting of that column. This is desired off course. 
However, the event 'GridViewSorted' isn't called and thus my second grid doesn't sort, which makes that my grids aren't sorted equally anymore. 

Does anybody have some advice on how to make sure my both grids are synchronized after a cell edit?
I've tried following already, but sorting on the 2nd grid just kicks in, when you enter and leave the same cell again after you've edited it. 

private void EndCellEdit(object sender, GridViewCellEditEndedEventArgs gridViewCellEditEndedEventArgs)
{
    var datagrid = sender as RadGridView;
    if (datagrid == null || !datagrid.Equals(EmployeeGrid)) return;
 
    FormationGrid.SortDescriptors.Replace(datagrid.SortDescriptors);
}





1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 29 Jan 2013, 01:47 PM
Hello,

I have tested the synchronization between two RadGridViews bound to the same ObservableCollection<MyClass> collection. Once the SortDescriptors were synchronized, then when I edited a value, the sorted columns were re-sorted automatically in both the GridViews. If your bound collection is a List<YourClass>, please change it to ObservableCollection<YourClass> and let me know is this helped.

Greetings,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Procurement
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or