【问题标题】:How can I get multiple lines using custom summary?如何使用自定义摘要获得多行?
【发布时间】:2019-05-15 15:49:23
【问题描述】:

我可以通过组合框中的一个选项获得总和。但我想打印几项的总和。

选择一个项目并输入一个值后,所有项目的输入值相加。

我该如何解决?

喜欢下面的图片 enter image description here

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;
}

【问题讨论】:

    标签: c# winforms devexpress


    【解决方案1】:

    我建议您使用类似于GridColumn.Summary 属性描述的示例 部分中说明的方法向列添加一些自定义摘要。之后,根据 CustomSummaryCalculatee.Item 参数识别每个摘要,并将所需的值分配给 e.TotalValue。

    另见:
    Summaries

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多