DataGrid PCV排序学习

最近工作中,使用到PCV排序,对PCV排序进行了简单的总结。

一般情况下,对结果集进行简单排序,我会直接使用OrderBy方法,如:

PagedCollectionView pcv = new PagedCollectionView(List.OrderByDescending(p=>p.rzdh));//融资单号排序

如果想要更复杂的排序,怎么办?比如要先按A升序,再B降序,再按C......,这就要使用新的方法。

ICollectionView接口定义了一个SortDescriptions集合,用以设置视图的排序规则,我们可以通过添加多个SortDescription对象来完成这种复合排序需求。如:

#region 通过PCV针对集合进行排序
PagedCollectionView pcv = new PagedCollectionView(List);
pcv.SortDescriptions.Clear();
var sortDescription1 = new System.ComponentModel.SortDescription("rzdh", System.ComponentModel.ListSortDirection.Descending);//融资单号降序
var sortDescription2 = new System.ComponentModel.SortDescription("zdrq", System.ComponentModel.ListSortDirection.Ascending);//制单日期升序
pcv.SortDescriptions.Add(sortDescription1);
pcv.SortDescriptions.Add(sortDescription2);
#endregion

总结如上,继续学习。

原文地址:https://www.cnblogs.com/prolovecui/p/4629417.html