【发布时间】:2017-06-11 05:57:41
【问题描述】:
我正在开发一个绑定到以下类集合的 wpf 数据网格
public class SalesData
{
public string SalesManName{ get; set; }
public int salesCount{ get; set; }
public string Area { get; set; }
public datetime salesdate{get;set;}
public int avgSales{ get; set; }
}
在我的 UI 中单击一个按钮,我正在执行以下操作
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(Datagrid.ItemsSource);
view.SortDescriptions.Add(new SortDescription("SalesCount", ListSortDirection.Descending));
PropertyGroupDescription groupDescription = new PropertyGroupDescription("SalesManName");
PropertyGroupDescription groupDescription2 = new PropertyGroupDescription("salesdate");
现在如果基本上发生的事情是它在数据网格中给我以下结果
SalesManName | SalesCount | Area | SalesDate
AAA | 2 | London | 05/06/2017
AAA | 1 | London | 05/07/2017
AAA | 1 | London | 05/08/2017
AAA | 2 | London | 05/09/2017
BBB | 2 | London | 05/06/2017
BBB | 2 | London | 05/07/2017
BBB | 2 | London | 05/09/2017
我想要的是
SalesManName | 05/06/2017 | 05/07/2017 | 05/08/2017 | 05/09/2017
AAA | 2 | 1 | 1 | 2
BBB | 2 | 2 | 0 | 2
【问题讨论】:
-
1) 在
view的GroupDescriptions中添加您添加组描述的代码。 2).GetDefaultView(Datagrid.ItemsSource)你是认真的吗?您需要在视图模型中创建集合,将其包装到ICollectionView并将DataGrid的ItemsSource绑定到此集合视图。 -
PropertyGroupDescription不是用来旋转数据的;如果您使用的是 MVVM,您可以自己在新数据结构中旋转您的SalesData集合并将其绑定到您的DataGrid。
标签: wpf wpfdatagrid