且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 datagridview 列中显示总和?

更新时间:2022-12-12 09:14:16

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();