gridcontrol自定义summary自定义计算公式(基本四则运算)

如上图所示,产品数量*每套单价=总价   显示在每套单价的footer里面:

方法1、

设置type为custom(自定义)   Tag为1    若是有很多自定义列,此处要来寻找具体的某一列

decimal customSum;
        private void gridView1_CustomSummaryCalculate ( object sender ,DevExpress.Data.CustomSummaryEventArgs e )
        {
            

            //若是多列  此处得到需要赋值的Tag标示
            int summaryId = Convert.ToInt32( ( e.Item as DevExpress.XtraGrid.GridSummaryItem ).Tag );
            //Initialization   加载gridcontrol控件
            if ( e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Start )
            {
                customSum = 0;
            }
            //Calculate   内部写计算方法
            if ( e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Calculate )
            {
                for ( int i = 0 ; i < gridView1.RowCount ; i++ )
                {
                    object x1 = gridView1.GetDataRow( i )["PQF06"];
                    x1 = ( x1 == DBNull.Value || x1 == null ) ? 0 : x1;
                    object x2 = gridView1.GetDataRow( i )["PQF09"];
                    x2 = ( x2 == DBNull.Value || x2 == null ) ? 0 : x2;

                    customSum += Math.Round( Convert.ToDecimal( x1 ) * Convert.ToDecimal( x2 ) ,2 );
                }
            }
            //Finalize   判断行  赋值
            if ( e.SummaryProcess == DevExpress.Data.CustomSummaryProcess.Finalize )
            {
                switch ( summaryId )
                {
                    case 1:
                    e.TotalValue = customSum;
                    break;
                }
            }
        }


方法2、

//直接获取两列的和然后做计算   不用先求和再计算
AN017.SummaryItem.SetSummary( DevExpress.Data.SummaryItemType.Custom ,Math.Round( Convert.ToDecimal( bandedGridView1.Columns["U1"].SummaryItem.SummaryValue ) / Convert.ToDecimal( bandedGridView1.GetDataRow( 0 )["AN006"] ) ,2 ).ToString( ) );


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值