Click here to Skip to main content
14,984,043 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.
Updated 21-May-11 1:45am

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):
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.

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 :)
Hope this[^] might help you.
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