Home Forums WPF controls Xceed DataGrid for WPF SortChanged event?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #24230 |

    In code-behind we need to detect when users click on the column headers to re-sort the grid. I can’t find the event to listen to, something like SortChanged — anyone?

    Thanks!

    Imported from legacy forums. Posted by Mark (had 646 views)

    Xceed Support
    Member
    Post count: 5658

    You can handle the CollectionChanged event of the SortDescriptions collection.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 318 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Jenny,

    CollectionChanged shows up as a protected event in the documentation, but DataGridCollectionView is a sealed class so I can’t derive a class from it to handle the event. Any work-around?

    Mark

    Imported from legacy forums. Posted by Mark (had 255 views)

    Xceed Support
    Member
    Post count: 5658

    SortDescriptions is a SortDescriptionCollection object and only exposes CollectionChanged as a protected event. Accessing it with the INotifyCollectionChanged interface reveals the public event.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 254 views)

    User (Old forums)
    Member
    Post count: 23064

    So like this?

    using System.Collections.Specialized;
    ((INotifyCollectionChanged)newView.SortDescriptions).CollectionChanged +=
    new NotifyCollectionChangedEventHandler(MyView_CollectionChanged);

    Seems to work. Tricky! Thanks.

    mark

    Imported from legacy forums. Posted by Mark (had 383 views)

    User (Old forums)
    Member
    Post count: 23064

    OK, the event is firing, but there’s a new problem. When the code is inside the event handler, the sort state is gone — sortdescriptions.count == 0. But my code logic in the event handler needs to know what’s going on with the sort. I’m assuming the grid is removing the sort before firing the event, then reinstating the new sort afterward. Is there someplace else in the chain of events I can detect the sort changing and at the same time have access to the sort state?

    Imported from legacy forums. Posted by Mark (had 418 views)

    Xceed Support
    Member
    Post count: 5658

    Yes, the grid clears the sort descriptions beforehand. What I can suggest is to handle the PreviewMouseLeftButtonDown event on the ColumnManagerRow and get your sort directions there before they are modified.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 5101 views)

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.