如何在C#中查找datagridview中的列总和 [英] How to find sum of columns in datagridview in C#
本文介绍了如何在C#中查找datagridview中的列总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要这样的答案:
I want the answer like this:
Column A Column B Column C
12.02 10.00 22.02
32.02 10.00 42.02
52.02
我的尝试:
What I have tried:
private void DgView_CellValidated(object sender, DataGridViewCellEventArgs e)
{
if (DgView.CurrentCell.ColumnIndex == 0)
{
DgView.Rows[DgView.CurrentCell.RowIndex].Cells[1].Value = cfun.convertdecimal(DgView.Rows[DgView.CurrentCell.RowIndex].Cells[0].Value.ToString()) + cfun.convertdecimal(txtValue.Text.ToString());
}
}
private void DgView_RowValidated(object sender, DataGridViewCellEventArgs e)
{
decimal sum = 0;
for (decimal i = 0; i < DgView.Rows.Count+1; ++i)
{
sum = cfun.convertdecimal(DgView.Rows[DgView.CurrentCell.RowIndex].Cells[1].Value.ToString())
+ cfun.convertdecimal(DgView.Rows[DgView.CurrentCell.RowIndex].Cells[2].Value.ToString());
}
DgView.Rows[DgASideView.CurrentCell.RowIndex].Cells[0].Value = sum.ToString();
}
当我尝试这个代码时,第1行第1列正在改变。想要在第2行第1列显示总和并且连续
when i try this code 1st row 1st column is changing.want to display the sum in 2nd row 1st column and continuously
推荐答案
在此处查看答案:数据网格视图中的数学计算 [< a href =https://www.codeproject.com/Answers/1268397/Math-calculation-in-datagrid-view#answer1\"target =_ blanktitle =New Window> ^ ]
并且:https://www.codeproject.com/Answers/1268855/How-to-sum-repeated-rows-in-datgridview-and-show-i#answer3
See answers here: Math calculation in datagrid view[^]
And: https://www.codeproject.com/Answers/1268855/How-to-sum-repeated-rows-in-datgridview-and-show-i#answer3
这篇关于如何在C#中查找datagridview中的列总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文