How to get the GroupInfoCollection.Key in the DataGrid_OnLoadingRowGroup eventHandler

Viewed 59

In the official MS documentation (https://docs.microsoft.com/de-de/windows/communitytoolkit/controls/datagrid_guidance/group_sort_filter) and also in the sample application (https://github.com/CommunityToolkit/WindowsCommunityToolkit/blob/b21dbe71f64e86ca9bb0ba6cfb4cb4d20e93765a/Microsoft.Toolkit.Uwp.SampleApp/Data/DataGridDataSource.cs#L167) they use the GroupInfoCollection class.

Grouping works just as well with an ObservableCollection. However, my question here is how do I get the GroupInfoCollection.Key in the DataGrid_OnLoadingRowGroup eventHandler or what was the Key property intended for?

I would like to mark the UI according to which key is currently grouped by. However, I currently lack this information.

1 Answers

my question here is how do I get the GroupInfoCollection.Key in the DataGrid_OnLoadingRowGroup eventHandler or what was the Key property intended for?

You could refer to offcial code sample line 124. RowGroupHeader has CollectionViewGroup property, if you set Range as key of group, you could get the key like following.

ICollectionViewGroup group = e.RowGroupHeader.CollectionViewGroup;
DataGridDataItem item = group.GroupItems[0] as DataGridDataItem;
var key = item.Range;         
e.RowGroupHeader.PropertyValue = key;
Related