本文主要是介绍DevExpress GridControl SummaryItem的Custom Summary,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
转自:http://blog.vsharing.com/janezhangxy/A1453525.html
使用DevExpress GridControl 时,有一栏为colSelected(FieldName 为"Selected") ,需根据此栏是否选中来计算另外一栏colCurrentApplyQuantity(FieldName 为"CurrentApplyQuantity")的Summary.
依据默认的SummaryItem是无法实现的,需要使用Custom Aggregate Functions. 具体处理过程如下:
1.设置Gridview OptionsView ShowFooter 为True,用来显示最终的Summary。
2.设置colCurrentApplyQuantity 的SummaryType为Custome ,Tag 为1.Tag是用来区分SummaryItem.如需要格式化显示的结果,可设置相应的DisplayFormat.
3.使用gridView1_CustomSummaryCalculate事件来实现依据colSelected来colCurrentApplyQuantity的Summary。 求和包括3个阶段,Initialization, Calculation 和Finalization。依据 CustomSummaryEventArgs.SummaryProcess的值来决定当前进行的那个阶段。具体实现如下:
int customSum;private void gridView1_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEventArgs e){int summaryID = Convert.ToInt32((e.Item as GridSummaryItem).Tag);GridView gridView = sender as GridView; // Initialization if (e.SummaryProcess == CustomSummaryProcess.Start){customSum = 0;}// Calculation if (e.SummaryProcess == CustomSummaryProcess.Calculate){bool isSelected = (bool)gridView.GetRowCellValue(e.RowHandle, "Selected");switch (summaryID){case 1: // The total summary calculated against the 'CurrentApplyQuantity' column. if (isSelected) customSum += Convert.ToInt32(e.FieldValue); break; }}// Finalization if (e.SummaryProcess == CustomSummaryProcess.Finalize){switch (summaryID){case 1:e.TotalValue = customSum;break;}} }
这篇关于DevExpress GridControl SummaryItem的Custom Summary的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!