Hi All,
I'm trying to Clone a row in DataGridView with the following code:
public DataGridViewRow CloneWithValues(DataGridViewRow row)
{
DataGridViewRow clonedRow = (DataGridViewRow)row.Clone();
for (Int32 index = 0; index < row.Cells.Count; index++)
{
clonedRow.Cells[index].Value = row.Cells[index].Value;
}
return clonedRow;
}Afterwards for example I want to copy this row 2 times with the following command piece of code:
dataGridView1.Rows.Insert(dataGridView1.CurrentRow.Index, _cloneRows);
When executing this line of code the 2nd time I get the following error:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
Additional information: Row provided already belongs to a DataGridView control.
What is wrong here that it is not possible to add several rows with the same content?
Thanks.