jdcoburn
asked on
DataGridViewRowCollection
hi - I'm using C# and ,net 4.
I'm trying to implement a copy and paste from a datagridview to a datagridview by row. it would seem that i can use the DataGridViewRowCollection that is returned from property "SelectedRows". after acquiring the collection, i use the method "CopyTo" to copy to an array of DGV rows. the count is correct. the documentation says "Copies the elements of the collection to the specified array, starting at the specified index."
but i then try to extract the cell value from each item in the collection and its null.
note that i'm using the cell index since it doesn't find the column name and throws an error. there are 8 items in teh row.
the code is below:
foreach (DataGridViewRow dgvRow in copyRows.AsEnumerable())
{
DataRow drg = CurrentScriptTable.NewRow( );
drg["script_Id"] = currentScript;
drg["lineNumber"] = scriptDisplay_DGV.CurrentR ow.Index + k;
drg["label"] = dgvRow.Cells[2].Value.ToSt ring();
CurrentScriptTable.Rows.In sertAt(drg , scriptDisplay_DGV.CurrentR ow.Index + k++);
}
any suggestions?
I'm trying to implement a copy and paste from a datagridview to a datagridview by row. it would seem that i can use the DataGridViewRowCollection that is returned from property "SelectedRows". after acquiring the collection, i use the method "CopyTo" to copy to an array of DGV rows. the count is correct. the documentation says "Copies the elements of the collection to the specified array, starting at the specified index."
but i then try to extract the cell value from each item in the collection and its null.
note that i'm using the cell index since it doesn't find the column name and throws an error. there are 8 items in teh row.
the code is below:
foreach (DataGridViewRow dgvRow in copyRows.AsEnumerable())
{
DataRow drg = CurrentScriptTable.NewRow(
drg["script_Id"] = currentScript;
drg["lineNumber"] = scriptDisplay_DGV.CurrentR
drg["label"] = dgvRow.Cells[2].Value.ToSt
CurrentScriptTable.Rows.In
}
any suggestions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Jim