如何使用主网格视图将每个细节网格视图的总和填充到主网格视图的页脚

本文关键字:网格 视图 填充 何使用 细节 | 更新日期: 2023-09-27 18:02:30

我正在使用主细节xtragrid,并希望使所有细节gridview的总和和填充在主gridview的页脚

如何使用主网格视图将每个细节网格视图的总和填充到主网格视图的页脚

我建议您按照如何在主网格视图列中显示按详细行计算的摘要示例

中所述,在主行的另一列中显示详细摘要信息。
//...
GridColumn colSubTotal = gridView1.Columns.AddField("SubTotal");
colSubTotal.UnboundType = DevExpress.Data.UnboundColumnType.Integer;
colSubTotal.Visible = true;
colSubTotal.Caption = "Budget";
gridView1.CustomUnboundColumnData += gridView1_CustomUnboundColumnData;
//...
void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e) {
    GridView view = sender as GridView;
    if(e.Column.FieldName != "SubTotal") return;
    if(!e.IsGetData) return;
    DataRow row = ((view.DataSource as IList)[e.ListSourceRowIndex] as DataRowView).Row;
    int subTotal = 0;
    foreach(DataRow childRow in row.GetChildRows("Project_Tasks")) 
        subTotal += (int)childRow["Budget"];
    e.Value = subTotal;
}

然后通过指定此附加列的摘要来显示所有详细信息的总摘要:

colSubTotal.Summary.Add(DevExpress.Data.SummaryItemType.Sum);
gridView1.OptionsView.ShowFooter = true;

设置aspx页面中gridview的showfooter属性为true在gridview的Grid_DataBound事件中对于页脚行,使页脚行的第一个单元格的列跨距等于网格中的列总数,并使除2以外的其余单元格不可见。向页脚行第一个单元格添加文本