I have a list which get dynamically filled. Within the lists the items are grouped. I am trying to sort the groups (not the items within the group) because somehow there are completely mixed up.
I was able to sort the items within the group but didn't find a way to programming sort the groups. Does anyone can give me a hint how to do it or why they are unsorted in the first place?
Init Code:
_lvUsers.ItemsSource = _config.listTestBenches;
CollectionView view = CollectionView)CollectionViewSource.GetDefaultView(_lvUsers.ItemsSource);
PropertyGroupDescription groupDescription = new PropertyGroupDescription("type");
view.GroupDescriptions.Add(groupDescription);
Update GUI:
ICollectionView view = CollectionViewSource.GetDefaultView(_config.listTestBenches);
view.Refresh();
This should help:
<CollectionViewSource Source="{Binding list}" x:Key="cvs">
<CollectionViewSource.SortDescriptions>
<!--This will sort groups-->
<scm:SortDescription PropertyName="type" />
<!--This will sort items-->
<scm:SortDescription PropertyName="sortItemName"/>
</CollectionViewSource.SortDescriptions>
<CollectionViewSource.GroupDescriptions>
<dat:PropertyGroupDescription PropertyName="type" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
Just att a SortDescription
to the same CollectionView
:
_lvUsers.ItemsSource = _config.listTestBenches;
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(_lvUsers.ItemsSource);
PropertyGroupDescription groupDescription = new PropertyGroupDescription("type");
view.GroupDescriptions.Add(groupDescription);
view.SortDescriptions.Add(new SortDescription("type", ListSortDirection.Ascending));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.