Lets say I have the following values that I’m loading into a datagrid
ID | Desc
------------------------
32 Red Cat
33 Blue Dog
34 Red Dog
37 Green Zebra
42 Reddish Snake
47 Greenlike Gorilla
I want to group my values on my data grid by the beginning colour specified in description. So it’ll be like this
ID | Desc
----------------------------
Red:
32 Red Cat
34 Red Dog
42 Reddish Snake
Blue:
33 Blue Dog
Green:
37 Green Zebra
47 Greenlike Gorilla
I have this for my code behind :
PagedCollectionView pageView = new PagedCollectionView(IEnumerable<MyClass> main);
pageView.GroupDescriptions.Add(new PropertyGroupDescription("")); //?????
this.MyGrid.ItemsSource = pageView;
How would I specify the grouping parameters?
You can provide an
IValueConverterto the GroupDescription. So use :where StringToColorConverter converts the Desc property to the color string:
Alternate approach
If you’re able to modify the class, then you could add a simple derived property
Color.Then you can group on it.