页脚摘要项目乘以某事物

时间:2017-07-12 13:18:02

标签: c# gridview devexpress

我使用DevExpress来显示特定值中的值的总和。

我的结果是有效的,但项目会成倍增加,原因我不知道:

enter image description here

这是怎么回事?

这是我初始化详细信息gridview

的功能
private void GridView_MasterRowExpanded(object sender, DevExpress.XtraGrid.Views.Grid.CustomMasterRowEventArgs e)
{
    //Initialize the details grid 
    GridView gridView = sender as GridView;
    GridView gridView1 = gridView.GetDetailView(e.RowHandle, e.RelationIndex) as GridView;
    gridView1.BeginUpdate();
    gridView1.Columns["ActivityID"].Visible = false;
    gridView1.Columns["ActivityID"].OptionsColumn.ShowInCustomizationForm = false;
    gridView1.Columns["IncidentID"].Visible = false;
    gridView1.Columns["Description"].OptionsColumn.ShowInCustomizationForm = false;
    gridView1.Columns["Description"].Width = 100;
    gridView1.Columns["TimeSpent"].Width = 0;
    gridView1.Columns["IsBillable"].Width = 50;
    gridView1.EndUpdate();

    //Initialize footer and show the sum of TimeSpent
    gridView1.OptionsView.ShowFooter = true;    gridView1.Columns["TimeSpent"].Summary.Add(DevExpress.Data.SummaryItemType.Sum, "TimeSpent", "Sum={0}");

}

1 个答案:

答案 0 :(得分:2)

每次调用事件时,您都会重新添加摘要(每当您展开主行以显示详细信息时)。

要解决此问题,请检查您是否已添加摘要:

if(gridView1.Columns["TimeSpent"].Summary.Count == 0)
   gridView1.Columns["TimeSpent"].Summary.Add(DevExpress.Data.SummaryItemType.Sum, 
                                              "TimeSpent", "Sum={0}");