【发布时间】:2019-08-02 17:14:18
【问题描述】:
我有一个带有预定义类的 ObservableCollection,目前 ObservableCollection 使用 ICollectionView 显示在 DataGrid 中,并按列 sl_Id、sl_Name、sl_Date 分组。
但是我想知道是否可以按 sl_struct 的索引进行分组,数组的长度是在运行时确定的。
public class SyncLog
{
public string sl_ID { get; set; }
public string sl_Name { get; set; }
public string sl_Date { get; set; }
public string sl_Type { get; set; }
public string[] sl_Struct { get; set; }
public string sl_SourceMachine { get; set; }
public string sl_Source { get; set; }
public string sl_DestMachine { get; set; }
public string sl_Dest { get; set; }
public bool sl_Success { get; set; }
public string sl_Time { get; set; }
public string sl_Size { get; set; }
}
当前分组代码
ICollectionView backupLogView = CollectionViewSource.GetDefaultView(Synclog);
PropertyGroupDescription group1 = new PropertyGroupDescription("sl_Id");
PropertyGroupDescription group2 = new PropertyGroupDescription("sl_Name");
PropertyGroupDescription group3 = new PropertyGroupDescription("sl_Date");
backupLogView.GroupDescriptions.Add(group1);
backupLogView.GroupDescriptions.Add(group2);
backupLogView.GroupDescriptions.Add(group3);
backupLogView.SortDescriptions.Add(new SortDescription("sl_Id", ListSortDirection.Ascending));
backupLogView.SortDescriptions.Add(new SortDescription("sl_Name", ListSortDirection.Ascending));
backupLogView.SortDescriptions.Add(new SortDescription("sl_Date", ListSortDirection.Ascending));
backupLogView.SortDescriptions.Add(new SortDescription("sl_Time", ListSortDirection.Ascending));
backupLogView.Refresh();
【问题讨论】:
标签: c# wpf grouping observablecollection icollectionview