1

In the official MS documentation (https://learn.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.

Dominic Jonas
  • 4,717
  • 1
  • 34
  • 77

1 Answers1

0

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;
Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
  • 1
    I would like to be able to group by different properties and not just by range, for example. So I never know by which property I have grouped before. Your solution assumes that I knew beforehand which property I was grouping by. My problem would be solved with the following approach https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/3089#issuecomment-604256939 because the current key is in `CollectionViewGroup.Group`. – Dominic Jonas May 18 '22 at 08:05
  • Good, if you have found the solution, please feel free answer below and accept it. – Nico Zhu May 18 '22 at 08:19