Xtragrid分组合计总计
第一步从数据库得到基本数据源,并增加几个空列用于存储合计的数据以及计算出来的合计百分比。
对查询出来的数据进行组装,就是用datatabl的computer方法对数据进行合计和计算
例如:dt.Compute("Sum(SALE_REAL_AMOUNT)", string.Format("UPSIDE_CODE like '{0}%'", tmp_big_type_code));
增加合计的列,要自定义合计的设定summmaryType为customer,
增加事件 gvReport_CustomDrawGroupRow
用于自定义分组内容的显示
private void gvReport_CustomDrawGroupRow(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e)
{
GridGroupRowInfo GridGroupRowInfo = e.Info as GridGroupRowInfo;
if (GridGroupRowInfo == null) return;
if (GridGroupRowInfo.Column.FieldName == "UPSIDE_CODE")
{
int i = gvReport.GetDataRowHandleByGroupRowHandle(e.RowHandle);
DataRow row = gvReport.GetDataRow(i);
GridGroupRowInfo.GroupText = row["UPSIDE_CODE"] + row["UPSIDE_NAME"].ToString();
}
}
CustomSummaryCalculate 用于自定义分组合计
private void gvReport_CustomSummaryCalculate(object sender, DevExpress.Data.CustomSummaryEventArgs e)
{
if (e.IsGroupSummary)
{
GridGroupSummaryItem item1=e.Item as GridGroupSummaryItem;
if (item1 == null) return;
if (item1.FieldName == "PER_AMOUNT")
{
item1.DisplayFormat = "{0}";
e.TotalValue = e.GetValue("PER_SUM_AMOUNT").ToString();
}
else if (item1.FieldName == "PRIFT_RATE")
{
item1.DisplayFormat = "{0}";
e.TotalValue = e.GetValue("SUM_PRIFT_RATE").ToString();//
}
}
}