如何使用自定义摘要获得多行



我可以在组合框中选择一个总和。但是我想打印几个项目的总和。

选择项目并输入值后,添加了所有项目的输入值。

我该如何修复?

如下图下图在此处输入图像描述

private void gridView_CellValueChanged(object sender, CellValueChangedEventArgs e)
{
    GridView view = sender as GridView;
    exchangeModel = new ExchangeModel();
    exchangeModel.CurrencyName = view.GetFocusedRowCellValue("CurrencyName").ToString();
    exchangeModel.Amount = Convert.ToInt32(view.GetFocusedRowCellValue("Amount").ToString());
}
private void gridView_CustomSummaryCalculate(object sender, CustomSummaryEventArgs e)
{
    if (e.SummaryProcess == CustomSummaryProcess.Start)
    {
        dictionary = new Dictionary<string, List<decimal>>();
    }
    if (e.SummaryProcess == CustomSummaryProcess.Calculate)
    {
        string currencyName = e.GetValue("CurrencyName").ToString();
        List<decimal> list;
        if (!dictionary.TryGetValue(currencyName, out list))
        {
            list = new List<decimal>();
            dictionary.Add(currencyName, list);
        }
        list.Add(Convert.ToInt32(e.GetValue("Amount")));
    }
    if (e.SummaryProcess == CustomSummaryProcess.Finalize)
    {
        e.TotalValue = CalculateTotal();
    }
}
private object CalculateTotal()
{
    decimal sum = 0;
    IEnumerator enumerator = dictionary.GetEnumerator();
    enumerator.Reset();
    while (enumerator.MoveNext())
    {
        KeyValuePair<string, List<decimal>> current = ((KeyValuePair<string, List<decimal>>)enumerator.Current);
        for (int i = 0; i < current.Value.Count; i++)
        {
            sum += current.Value[i];
        }
    }
    return sum;
}

我建议您使用类似于Gridcolumn.summary属性描述的示例部分中所示的方法向列添加一些自定义摘要。之后,基于 customsummarycalculate 's e.item 参数,并将所需值分配给E.TotalValue。

另请参见:
摘要

最新更新