Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

C#
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(dataGridView1);
row.Cells[0].Value = 1;


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"
C#
row.Cells["ID"].Value = i;// it gives error

But if I access it for any previous row then I am not getting any error
C#
dataGridView1.Rows[0].Cells["ID"]=1;//it works fine

In above case it works fine.

So, what can be problem in first case?
Posted
Updated 17-Aug-10 22:46pm
v2

1 solution

The row is not part of your dataGridView1. Try adding it to the dataGridView1 after you create it!
dataGridView1.Rows.Add(row);
 
Share this answer
 
v2
Comments
Toli Cuturicu 19-Aug-10 10:32am    
"thnx for response
i have added that row in datagrid but i did nt mention in above code.
after adding row still same problem."
[I moved here this fake answer by the op]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900