数据网格视图添加错误 [英] Data grid view adding error
本文介绍了数据网格视图添加错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想添加第1行和第2行并将其显示在第3行但是我遇到了一些错误可以有人请帮忙谢谢
I want to add row 1 and row 2 and get it displayed on row 3 but I am facing some errors can someone please help thanks
private void button2_Click(object sender, EventArgs e) /// Click button it will do the adding
{
String a; // total value for row 3 cell 0
dataGridView1.Rows[1].Cells[0].Value.ToString();
dataGridView1.Rows[2].Cells[0].Value.ToString();
Convert.ToDouble(dataGridView1.Rows[1].Cells[0].Value);
Convert.ToDouble(dataGridView1.Rows[2].Cells[0].Value);
a = dataGridView1.Rows[1].Cells[0].Value + dataGridView1.Rows[1].Cells[0].Value;
dataGridView1.Rows[3].Cells[0].Value = a;
String b;// total value for row 3 cell 1
dataGridView1.Rows[1].Cells[1].Value.ToString();
dataGridView1.Rows[2].Cells[1].Value.ToString();
b = dataGridView1.Rows[1].Cells[1].Value.ToString() + dataGridView1.Rows[1].Cells[1].Value.ToString();
dataGridView1.Rows[3].Cells[1].Value = b;
String c;// total value for row 3 cell 2
dataGridView1.Rows[1].Cells[2].Value.ToString();
dataGridView1.Rows[2].Cells[2].Value.ToString();
c = dataGridView1.Rows[1].Cells[2].Value.ToString() + dataGridView1.Rows[1].Cells[2].Value.ToString();
dataGridView1.Rows[3].Cells[2].Value = c;
String d;// total value for row 3 cell 3
dataGridView1.Rows[1].Cells[3].Value.ToString();
dataGridView1.Rows[2].Cells[3].Value.ToString();
d = dataGridView1.Rows[1].Cells[3].Value.ToString() + dataGridView1.Rows[1].Cells[3].Value.ToString();
dataGridView1.Rows[3].Cells[3].Value = d;
String f;// total value for row 3 cell 4
dataGridView1.Rows[1].Cells[4].Value.ToString();
dataGridView1.Rows[2].Cells[4].Value.ToString();
f = dataGridView1.Rows[1].Cells[4].Value.ToString() + dataGridView1.Rows[1].Cells[4].Value.ToString();
dataGridView1.Rows[3].Cells[4].Value = f;
String g;// total value for row 3 cell 5
dataGridView1.Rows[1].Cells[5].Value.ToString();
dataGridView1.Rows[2].Cells[5].Value.ToString();
g = dataGridView1.Rows[1].Cells[5].Value.ToString() + dataGridView1.Rows[1].Cells[5].Value.ToString();
dataGridView1.Rows[3].Cells[5].Value = g;
String h;// total value for row 3 cell 6
dataGridView1.Rows[1].Cells[6].Value.ToString();
dataGridView1.Rows[2].Cells[6].Value.ToString();
h = dataGridView1.Rows[1].Cells[6].Value.ToString() + dataGridView1.Rows[1].Cells[6].Value.ToString();
dataGridView1.Rows[3].Cells[6].Value = h;
String i;// total value for row 3 cell 7
dataGridView1.Rows[1].Cells[7].Value.ToString();
dataGridView1.Rows[2].Cells[7].Value.ToString();
i = dataGridView1.Rows[1].Cells[7].Value.ToString() + dataGridView1.Rows[1].Cells[7].Value.ToString();
dataGridView1.Rows[3].Cells[7].Value = i;
String j;// total value for row 3 cell 8
dataGridView1.Rows[1].Cells[8].Value.ToString();
dataGridView1.Rows[2].Cells[8].Value.ToString();
j = dataGridView1.Rows[1].Cells[8].Value.ToString() + dataGridView1.Rows[1].Cells[8].Value.ToString();
dataGridView1.Rows[3].Cells[8].Value = j;
String k;// total value for row 3 cell 9
dataGridView1.Rows[1].Cells[9].Value.ToString();
dataGridView1.Rows[2].Cells[9].Value.ToString();
k = dataGridView1.Rows[1].Cells[9].Value.ToString() + dataGridView1.Rows[1].Cells[9].Value.ToString();
dataGridView1.Rows[3].Cells[9].Value = k;
String l;// total value for row 3 cell 10
dataGridView1.Rows[1].Cells[10].Value.ToString();
dataGridView1.Rows[2].Cells[10].Value.ToString();
j = dataGridView1.Rows[1].Cells[10].Value.ToString() + dataGridView1.Rows[1].Cells[10].Value.ToString();
dataGridView1.Rows[3].Cells[10].Value = j;
String n;// total value for row 3 cell 11
dataGridView1.Rows[1].Cells[11].Value.ToString();
dataGridView1.Rows[2].Cells[11].Value.ToString();
n = dataGridView1.Rows[1].Cells[11].Value.ToString() + dataGridView1.Rows[1].Cells[11].Value.ToString();
dataGridView1.Rows[3].Cells[11].Value = n;
}
Graph Errpr.jpg - Google Drive [ ^ ]
我的尝试:
我曾尝试过转换为双倍但仍然出错
Graph Errpr.jpg - Google Drive[^]
What I have tried:
I had tried converting to double but still error
推荐答案
全错了!正如我在问题的评论中提到的,你必须使用正确的数据类型!
似乎,你想在第三行中添加两行的总和 - 对于每一列。因此,您的代码可以简化为:
All wrong! As i mentioned in the comment to the question, you have to use proper data type!
Seems, you want to add a sum of two rows in the third one - for each column. So, your code can be simplified to:
for(int i=0; i<12; i++)
{
dataGridView1.Rows[2].Cells[i].Value = dataGridView1.Rows[0].Cells[i].Value + dataGridView1.Rows[1].Cells[i].Value;
}
这篇关于数据网格视图添加错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文