如何在 datagridview 列中显示总和? [英] how I can show the sum of in a datagridview column?
本文介绍了如何在 datagridview 列中显示总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要显示此 datagridview
中 count
列的总和,但我不知道如何获取 datagridview 中的数据.>
当我点击按钮时,我想在label1
中显示94
.
如何做到这一点?
解决方案
int sum = 0;for (int i = 0; i < dataGridView1.Rows.Count; ++i){sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value);}label1.Text = sum.ToString();
I need to show the sum of the count
column from this datagridview
, but I don't know how I can get to the data in the datagridview.
When I click on the button, I want to show 94
in label1
.
How can this be done?
解决方案
int sum = 0;
for (int i = 0; i < dataGridView1.Rows.Count; ++i)
{
sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value);
}
label1.Text = sum.ToString();
这篇关于如何在 datagridview 列中显示总和?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文