C#DataGridView方法行。ADD工作不正确 - 它在上一个上添加行,而不是最后
我对datagridview.rows.add方法有问题。我想添加一条新行,但在最后一行,而不是以前。我不知道为什么在这种情况下该方法添加不起作用。我的代码:
dataGridView1.RowCount = 3;
dataGridView1.ColumnCount = 4;
dataGridView1.Rows[0].Cells[0].Value = 1;
dataGridView1.Rows[0].Cells[1].Value = 2;
dataGridView1.Rows[0].Cells[2].Value = 3;
dataGridView1.Rows[0].Cells[3].Value = 4;
dataGridView1.Rows[1].Cells[0].Value = 5;
dataGridView1.Rows[1].Cells[1].Value = 6;
dataGridView1.Rows[1].Cells[2].Value = 7;
dataGridView1.Rows[1].Cells[3].Value = 8;
dataGridView1.Rows[2].Cells[0].Value = 9;
dataGridView1.Rows[2].Cells[1].Value = 10;
dataGridView1.Rows[2].Cells[2].Value = 11;
dataGridView1.Rows[2].Cells[3].Value = 12;
dataGridView1.Rows.Add(13,14,15,16);
和结果:
我会为任何帮助或建议而感到兴奋!
I have a problem with datagridview.Rows.Add method. I want to add a new line but in the last line, not in previous. I don't know why the method Add doesn't work in this case. My code:
dataGridView1.RowCount = 3;
dataGridView1.ColumnCount = 4;
dataGridView1.Rows[0].Cells[0].Value = 1;
dataGridView1.Rows[0].Cells[1].Value = 2;
dataGridView1.Rows[0].Cells[2].Value = 3;
dataGridView1.Rows[0].Cells[3].Value = 4;
dataGridView1.Rows[1].Cells[0].Value = 5;
dataGridView1.Rows[1].Cells[1].Value = 6;
dataGridView1.Rows[1].Cells[2].Value = 7;
dataGridView1.Rows[1].Cells[3].Value = 8;
dataGridView1.Rows[2].Cells[0].Value = 9;
dataGridView1.Rows[2].Cells[1].Value = 10;
dataGridView1.Rows[2].Cells[2].Value = 11;
dataGridView1.Rows[2].Cells[3].Value = 12;
dataGridView1.Rows.Add(13,14,15,16);
And result:
I will be thrilled for any help or advice!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个更好的想法是不要设置
rowcount
何时进入新行。因此,如果可以继续阅读。在下面的示例中,没有断言要验证
row.cell.cells [3] .Value
是一个INT,但在第二个块中显示了如何正确检查。servert单元格值可以表示
int
A better idea is not to set
RowCount
when you will be entering new rows. So if open to a alternate read on.In the example below there is no assertion to validate
row.Cells[3].Value
is an int but in the 2nd block shows how to check correctly.Assert cell value can represent an
int
这是在网格视图中插入一条线的正确方法:
标记为 *的最后一行实际上是新线路的占位符,最好不要直接插入它

This is the correct way to insert a line in a grid view:
The last line marked with * is in fact a placeholder for new lines and it is better not to insert it directly
