需求:对C1DataGrid某列进行统计并显示在C1DataGrid最后一行
尝试:参考样例GrandTotal,采用C1.WPF.DataGrid.Summaries中的DataGridAggregateSum方法等,实现了合计并显示的效果
问题:采用C1DataGrid 的 AutoGeneratingColumn事件,调用合计方法时,必须设置AutoGenerateColumns="True"。但是这样会使列表绑定的Model里面所有的属性全部显示到列表上了,请问如何避免呢?
控件:Studio for WPF
主要代码:
.xaml.文件部分
- <c1:C1DataGrid Grid.Row="3" Name="OrderDataGrid" IsReadOnly="True"
- ColumnHeaderHeight="35" CanUserAddRows="False" CanUserEditRows="False"
- ItemsSource="{Binding OrderList}" AutoGenerateColumns="True"
- FrozenBottomRowsCount="1" AutoGeneratingColumn="OrderDataGrid_AutoGeneratingColumn" >
- <c1:C1DataGrid.Columns>
- <c1:DataGridTextColumn Header="订单号" Binding="{Binding COSourceNo}" MinWidth="90"/>
- <c1:DataGridTextColumn Header="订单类型" Binding="{Binding OrderTypeStr}" MinWidth="80"/>
- <c1:DataGridTextColumn Header="产品规格" Binding="{Binding Piece}" MinWidth="120"/>
- <c1:DataGridTextColumn Header="产品数量" Binding="{Binding ProductQuantity}" MinWidth="70"/>
- <c1:DataGridTextColumn Header="总面积" Binding="{Binding ProductTotalArea}" MinWidth="80"/>
- <c1:DataGridTextColumn Header="下单时间" Binding="{Binding CreatedOnStr}" MinWidth="100"/>
- </c1:C1DataGrid.Columns>
- <c1:C1DataGrid.BottomRows>
- <c1:DataGridSummaryRow/>
- </c1:C1DataGrid.BottomRows>
- </c1:C1DataGrid>
复制代码
.xaml.cs文件部分
- private void OrderDataGrid_AutoGeneratingColumn(object sender, C1.WPF.DataGrid.DataGridAutoGeneratingColumnEventArgs e)
- {
- if (e.Property.Name == "ProductQuantity")
- {
- DataGridAggregate.SetAggregateFunctions(e.Column,
- new DataGridAggregatesCollection
- {
- new DataGridAggregateSum { ResultFormat = "SUM = {0}" },
- new DataGridAggregateAvg { ResultFormat = "AVG = {0}" },
- });
- }
- }
复制代码 |
|