DevExpress 表格显示分组小计与总计(GroupSummary.Add)
DevExpress表格支持两种小计显示样式
1、小计在分组下面显示
2、小计在分组行显示
C#源码
C# 全选
private void Form2_Load(object sender, EventArgs e)
{
gc.DataSource = DemoData.GetGoodsList();
//设置分组=SUM
gv.GroupSummary.Add(new DevExpress.XtraGrid.GridGroupSummaryItem
{
FieldName = "Qty",
SummaryType = DevExpress.Data.SummaryItemType.Sum,
DisplayFormat = "{0:0.##}",
ShowInGroupColumnFooter = colQty, //重要!在分组行下面显示
});
//设置分组=AVG
gv.GroupSummary.Add(new DevExpress.XtraGrid.GridGroupSummaryItem
{
FieldName = "Price",
SummaryType = DevExpress.Data.SummaryItemType.Average,
DisplayFormat = "{0:0.##}",
ShowInGroupColumnFooter = colPrice,
});
//设置分组=SUM
gv.GroupSummary.Add(new DevExpress.XtraGrid.GridGroupSummaryItem
{
FieldName = "Amount",
SummaryType = DevExpress.Data.SummaryItemType.Sum,
DisplayFormat = "{0:0.##}",
ShowInGroupColumnFooter = colAmount,
ShowInGroupColumnFooterName = "Amount",
});
//客户名称分组显示
gv.Columns["CustomerName"].GroupIndex = 0;
//自动扩展所有分组,显示所有记录
gv.ExpandAllGroups();
}
C# 全选
//小计样式1 - 小计在分组最下面
private void button1_Click(object sender, EventArgs e)
{
gv.OptionsBehavior.AllowPartialGroups = DevExpress.Utils.DefaultBoolean.False;
gc.RefreshDataSource();
gv.ExpandAllGroups();
}
//小计样式2 - 小计在分组行显示
private void button2_Click(object sender, EventArgs e)
{
gv.OptionsBehavior.AllowPartialGroups = DevExpress.Utils.DefaultBoolean.True;
gc.RefreshDataSource();
gv.ExpandAllGroups();
}
3、清除分组
C# 全选
gv.ClearGrouping();
ERP系统实现效果
C# 全选
//小计在分组最下面
gvSummary.OptionsBehavior.AllowPartialGroups = DevExpress.Utils.DefaultBoolean.False;
//设置分组=SUM
gvSummary.GroupSummary.Add(new DevExpress.XtraGrid.GridGroupSummaryItem
{
FieldName = "TotalOrderQty",
SummaryType = DevExpress.Data.SummaryItemType.Sum,
ShowInGroupColumnFooter = colTotalOrderQty, //订单数量
});
//设置分组=SUM
gvSummary.GroupSummary.Add(new DevExpress.XtraGrid.GridGroupSummaryItem
{
FieldName = "TotalQty",
SummaryType = DevExpress.Data.SummaryItemType.Sum,
ShowInGroupColumnFooter = colTotalQty, //发货数量
});
//设置分组=SUM
gvSummary.GroupSummary.Add(new DevExpress.XtraGrid.GridGroupSummaryItem
{
FieldName = "TotalAmount",
SummaryType = DevExpress.Data.SummaryItemType.Sum,
DisplayFormat = "{0:0.##}",
ShowInGroupColumnFooter = colTotalAmount, //金额
});
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网