WPF DEV gridcontrol 自定义计算列(TotalSummary)
/// <summary> /// 自定义计算列 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void user_GridControl_CustomSummary(object sender, CustomSummaryEventArgs e) { try {foreach (var item in dic) if (item.Key == ((GridSummaryItem)e.Item).FieldName) if (e.IsTotalSummary) if (e.SummaryProcess == CustomSummaryProcess.Start) e.TotalValue = item.Value; } catch (Exception ex) { } }
//生成数据的时候 user_GridControl.TotalSummary.Clear(); foreach (DataColumn item in source.Columns) user_GridControl.TotalSummary.Add(new GridSummaryItem() { SummaryType = DevExpress.Data.SummaryItemType.Custom, FieldName = item.ColumnName, DisplayFormat = item.ColumnName + "的和:{0}" });
XAML
<dxg:GridControl x:Name="user_GridControl" CustomSummary="user_GridControl_CustomSummary" FilterChanged="user_GridControl_FilterChanged" AutoExpandAllGroups="True" AutoPopulateColumns="True" ScrollViewer.CanContentScroll="True" AllowColumnMRUFilterList="True" dx:ScrollBarExtensions.ScrollBarMode="TouchOverlap" Margin="5" Grid.Row="1"> <dxg:GridControl.GroupSummary> <dxg:GridSummaryItem SummaryType="Count" /> </dxg:GridControl.GroupSummary> <dxg:GridControl.View> <dxg:TableView AllowEditing="False" BestFitMode="VisibleRows" WheelScrollLines="1" RowMinHeight="30" x:Name="SummaryTable" AllowMoveColumnToDropArea="False" ShowGroupPanel="False" AllowGrouping="True" AllowBandMoving="True" AllowResizing="True" AllowBestFit="True" ShowSearchPanelMode="Always" ShowIndicator="True" ShowAutoFilterRow="True" NavigationStyle="Row" RowAnimationKind="Custom" WaitIndicatorType="Default" ShowFixedTotalSummary="False" AllowScrollAnimation="True" AllowFixedGroups="True" ColumnFilterPopupMode="Default" AllowChangeBandParent="False" AllowPerPixelScrolling="True" ShowTotalSummary="True" ShowFilterPanelMode="ShowAlways" > </dxg:TableView> </dxg:GridControl.View> </dxg:GridControl>