I have an ObservableCollection with a predefined class, Currently the ObservableCollection is displayed in a DataGrid using ICollectionView and grouped by columns sl_Id, sl_Name, sl_Date.
However i would like to know if its possible to group by the index's of sl_struct, the length of the array is determined at runtime.
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; }
}
current code for grouping
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();
If
new PropertyGroupDescription("sl_Struct.Length")doesn't work, though it probably should, you can just add another property to your SyncLog class that returnssl_Struct.LengthIf you can't add a property to the
SyncLogclass(for example, if it is some external DTO), then you should probably create a specialized SyncLogViewModel that wraps the regularSyncLogand adds thesl_StructLength