Posted on 2013-01-20
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.CurrentRow.Index + k;
drg["label"] = dgvRow.Cells.Value.ToString();
CurrentScriptTable.Rows.InsertAt(drg, scriptDisplay_DGV.CurrentRow.Index + k++);