Home Forums WPF controls Xceed DataGrid for WPF sort changed & column order changed events?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #23832 |

    I’m using the WPF DataGridControl in TableView mode to display a collection of objects in a DataGridCollectionView, and want to detect when the Grouping, Sorting, and Column Order changes so that I can keep track of the user’s organization of the data.

    I’ve figured out to use the DataCollectionView’s GroupDescriptions.CollectionChanged event to determine when groupings have changed, but can’t seem to figure out what event to respond to for Sorting & Column Order changes.

    I’ve seen references in the forums to a column’s SortDirectionChanged event and the grid’s SortedColumnsChanged event, but neither the 1.1 documentation nor intellisense seem to find these events.

    I’ve tried hooking into the DataGridControl’s Columns.CollectionChanged event and the Column’s PropertyChanged event, but these don’t seem to fire when re-ordering and sorting.

    Any thoughts? Am I missing something?


    Imported from legacy forums. Posted by Mike (had 1107 views)

    Xceed Support
    Post count: 5658


    To detect sorting changes, you can observe the DataGridCollectionView’s SortDescriptions collection as well…

    For the Column re-ordering, you could observe the DataGridControl’s VisibleColumns collection.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 668 views)

    User (Old forums)
    Post count: 23064

    I think what I was missing or not fully understanding was that:

    * GroupDescriptions is an ObservableCollection object and therefore exposes CollectionChanged publicly

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

    The following seems to work…

    DataGridCollectionView sourceView = this.PART_DataGrid.ItemsSource as DataGridCollectionView;

    if (sourceView != null)

    // observe the Grouping Collection Changed event
    sourceView.GroupDescriptions.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(GroupDescriptions_CollectionChanged);

    // observe the Sorting Collection Changed event
    System.Collections.Specialized.INotifyCollectionChanged sortingCollection = (System.Collections.Specialized.INotifyCollectionChanged)sourceView.SortDescriptions;
    sortingCollection.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(SortDescriptions_CollectionChanged);


    If there’s a better way to do this, please let me know…


    Imported from legacy forums. Posted by Mike (had 3800 views)

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