Automatic sorting event when cell is edited

2 posts, 0 answers
  1. Procurement
    Procurement avatar
    1 posts
    Member since:
    Oct 2009

    Posted 28 Jan 2013 Link to this post

    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);
    }





  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 29 Jan 2013 Link to this post

    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.

Back to Top