如何在 datagridview 列中显示总和? [英] how I can show the sum of in a datagridview column?

查看:48
本文介绍了如何在 datagridview 列中显示总和?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要显示此 datagridviewcount 列的总和,但我不知道如何获取 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆