访问datagridview单元时出现问题 [英] Problem in accessing datagridview cell
本文介绍了访问datagridview单元时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi,
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(dataGridView1);
row.Cells[0].Value = 1;
在上面提到的代码中,如果我尝试使用其名称访问行的第一个单元格,则会收到错误消息"大声列"ID"不存在"
In above mentioned code, if I try to access row''s first cell with it''s name then I get error that "coloumn ''ID'' does not exist"
row.Cells["ID"].Value = i;// it gives error
但是,如果我在上一行访问它,那么我不会收到任何错误
But if I access it for any previous row then I am not getting any error
dataGridView1.Rows[0].Cells["ID"]=1;//it works fine
在上述情况下,它可以正常工作.
因此,在第一种情况下可能会出现问题?
In above case it works fine.
So, what can be problem in first case?
推荐答案
row
不属于dataGridView1
的一部分.创建它后,尝试将其添加到dataGridView1
!
Therow
is not part of yourdataGridView1
. Try adding it to thedataGridView1
after you create it!
dataGridView1.Rows.Add(row);
这篇关于访问datagridview单元时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文