如何添加DataGridView的列项 [英] How Do I Add Column's Items Of A DataGridView

查看:63
本文介绍了如何添加DataGridView的列项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人请知道如何在datagridview中添加项目总和

Does anyone please know how to add the sum of items in a datagridview

推荐答案

请查看此链接



http://www.ezzylearning.com/tutorial/displaying-total-格栅内页 [ ^ ]


http://www.aspsnippets.com/Articles/Display-sum-of-Columns-total-in-GridView-Footer-in-ASPNet- using-C-and-VBNet.aspx [ ^ ]

http://www.encodedna.com/2013/06/sum-of-gridview-column-in-footer.htm [ ^ ]





-KR
http://www.aspsnippets.com/Articles/Display-sum-of-Columns-total-in-GridView-Footer-in-ASPNet-using-C-and-VBNet.aspx[^]
http://www.encodedna.com/2013/06/sum-of-gridview-column-in-footer.htm[^]


-KR


你可以通过多种方式实现。

You can do it by many ways.
int sum = 0;
for (int i = 0; i < dataGridView1.Rows.Count; ++i)
{
    sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value);
}





你可以使用Linq



You can use Linq

int sum= dataGridView1.Rows.Cast<datagridviewrow>()
                .Sum(t => Convert.ToInt32(t.Cells[1].Value));





,最后你可以在gridview上添加一行,或者你可以在Label中显示总和结果。



and finally you can add a Row on your gridview or you can show sum result in Label .


这篇关于如何添加DataGridView的列项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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