Click here to Skip to main content
15,886,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

How to add datarow in to a datagridview...
I am facing Conversion problem..
i got an error like this

"Cannot convert type 'System.Data.DataRow' to 'System.Windows.Forms.DataGridViewRow'"

Please help me in this regard.

Thanks in Advance.
Posted
Updated 21-May-11 1:45am
v2

Well, not sure what you want to do, I would need to see some of your code for that.
But the easiest way to do this (not using any binding and such):
C#
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(dgv); // dgv is your DataGridView.
// Add values to the Cells.			
// Make sure these columns actually exist!
row.Cells["column1"].Value = dr["someColumn1"]; // dr is your DataRow.
row.Cells["column2"].Value = dr["someColumn2"];
// Add the row to the DataGridView.
dgv.Rows.Add(row);


The problem with this solution is that if your DataRow changes this code might break.
So if the DataRow comes from a database and the database is altered you need to alter this piece of code. But that is what happens if you do not use binding I guess.
If you do use binding I am not sure I see the problem, since the DataGridView should update automatically :)
 
Share this answer
 
v2
Hope this[^] might help you.
 
Share this answer
 
Comments
version_2.0 21-May-11 7:58am    
plz tell me in C#...

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