Я могу получить сумму одним выбором в поле со списком. Но я хочу напечатать сумму каждого из нескольких пунктов.
После выбора элемента и ввода значения добавляются входные значения всех элементов.
Как я могу это исправить?
Как показано ниже
введите описание изображения здесь
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;
}