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;
                }
            }      
        }

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值