DevExpress GridControl SummaryItem的Custom Summary

来源:互联网 发布:帝国cms自动采集发布 编辑:程序博客网 时间:2024/05/18 00:22

转自: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;                }            }              }

0 0
原创粉丝点击