如上图所示,产品数量*每套单价=总价 显示在每套单价的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( ) );