Well...
In case when a
DataGridView[
^] control is bound with datatable, you can't create a copy of
DataGridViewRow[
^] object.
MSDN documentation states:
Remarks
You can use the Rows collection to manually populate a DataGridView control instead of binding it to a data source.
See:
DataGridView.Rows[
^]
Conclusion: you have to add a "row" (record) to your datatable!
Steps to do:
1) get selected
DataGridViewRow
and read the value of cell which is unique
2) find that unique value in a datatable
3) add a copy of
DataRow[
^] to the DataTable object
Dim dt As DataTable = DirectCast(dgv.DataSource, DataTable)
Dim ValueToFind = ...
Dim rowToCopy = dt.AsEnumerable() _
.Where(Function(x) x.Field(Of Integer)("FieldName") = ValueToFind) _
.FirstOrDefault()
Dim nr = dt.NewRow()
nr.ItemArray = rowToCopy.ItemArray
dt.Rows.Add(nr)
dgv.DataSource = dt
Note: An exact copy of DataRow is not allowed in case of primary key violation.