使用列中的最后一个值进行汇总而不是 SUM

Use Last Value in Column for Summary Instead of SUM

我有以下代码删除检索 UI 事件的摘要 row/band 值。我确定这是错误的方法,但它确实有效。

public UiEventResult AfterRetrieveData_111(object sender, RetrieveDataEventArgs e)
    {
        UltraGridBase baseGrid = _view.ViewGrids["ultraGrid1"];
        UltraGridLayout gridLayout = baseGrid.DisplayLayout;
        
        for (int i = 0; i < 2; i++)
        {
            gridLayout.Bands[i].Columns["columnA"].Formula = "''";
        }
        for (int i = 0; i < 3; i++)
        {
            gridLayout.Bands[i].Columns["columnB"].Formula = "''";
            gridLayout.Bands[i].Columns["columnC"].Formula = "''";
        }

有没有一种方法可以对检索进行编程,使其填充列 A/band[2] 的摘要行,以便使用每列中的最后一个值?如果没有上面的代码,它将对下面的行求和,但希望有一种方法可以使用最后一行的值。数据将始终按日期降序排列,因此最后一行始终是所需的值...

实现此目的的一种方法是在 InitializeRowEvent 中将 columnA 的值设置为子带中最后一行的值,如下所示:

// Update the rows only in the first band. You can also use e.Row.Band.Key == {YOU_BAND_KEY}
if (e.Row.Band.Index == 0)
{
    // set the value of the columnA to the value of the last row in the child band
    e.Row.Cells["columnA"].Value = e.Row.ChildBands.LastRow.Cells["columnA"].Value;
}

请注意,如果您编辑单元格值,这将不起作用。如果您需要在单元格更新后更新父行值,您可以再次在 InitializeRowEvent 中添加:

// look for row in the secon band
if (e.Row.Band.Index == 1)
{
    // get the last row in the second band
    if (e.Row == e.Row.ParentRow.ChildBands.LastRow)
    {
        // get the value of the last row in the second band and set it to the parent row
        e.Row.ParentRow.Cells["columnA"].Value = e.Row.Cells["columnA"].Value;
    }
}

这将遍历 ChildBand 并将父行值设置为每个 ChildBand 中的最后一个值。

int rowCount = gridLayout.Rows.Count;
for (int i = 0; i < rowCount; i++)
{
foreach (UltraGridChildBand childBand in baseGrid.Rows[i].ChildBands)
     {
      foreach (UltraGridRow row in childBand.Rows)
          {
           row.Cells["columnA"].Value =row.ChildBands.LastRow.Cells["columnA"].Value;
          }
     }
            
}