如何获取datagridview(windows应用程序)页脚的总行数 [英] How to get total sum of rows at the footer of datagridview (windows application)
本文介绍了如何获取datagridview(windows应用程序)页脚的总行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法获得datagridview页脚的行总数
我的桌子是
I couldn't get the sum total of rows at the footer of datagridview
my table is
id purticulars debit credit
1 ammu 200 0
2 chinnu 300 0
3 annie 0 500
4 mittu 0 500
我希望输出为
I want output as
id purticulars debit credit
1 ammu 200 0
2 chinnu 300 0
3 annie 0 500
4 mittu 0 500
-----------------------------------------
total 500 1000
我尝试了什么:
我试过这个
What I have tried:
I have tried this
for (int m = 1; m < dt.Columns.Count; m++)
{
double sum = 0;
for (int j = 0; j < dt.Rows.Count; j++)
{
sum += Convert.ToDouble(dt.Rows[j][m]);
dataGridView1.Rows[dt.Rows.Count].Cells[m + 1].Value = sum.ToString();
}
但它显示错误,因为输入字符串格式不正确
But it shows error as input string is not in correct format
推荐答案
您正在迭代的某些单元格不包含可以转换为double的值。调试for循环,你必须确定问题。您还应该考虑使用TryParse
进行转换。
您从第二列(索引1)循环来自你的帖子没有数字
Some of the cells you are iterating do not contain a value which can be converted to double. Debug the for loop you have to identify the issue. You should also consider usingTryParse
for conversion.
You are looping from second column (index 1) which from your post is not having numbers
这篇关于如何获取datagridview(windows应用程序)页脚的总行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文