我想知道如何在另一个DataGridView中复制一行。它们与数据表绑定。我正在尝试这个,但它不起作用!
For k As Integer = 0 To gridA.SelectedRows.Count
Dim row As DataRow = dtA.Rows(gridA.SelectedRows(k).Index)
dtB.ImportRow(row)
Next
然后从gridA中删除行:
For k As Integer = 0 To gridA.SelectedRows.Count
dtA.Rows.RemoveAt(gridA.SelectedRows(k).Index)
Next
答案 0 :(得分:0)
使用数据网格的索引可能会出现问题,因为行的排序顺序可能与DataTable的顺序不同。
我重复了你的例子,使用实际的行对象来移动和删除:
Dim rows As DataGridViewSelectedRowCollection = gridA.SelectedRows
For Each row As DataGridViewRow In rows
dtB.ImportRow(DirectCast(row.DataBoundItem, DataRowView).Row)
Next
For Each row As DataGridViewRow In rows
dtA.Rows.Remove(DirectCast(row.DataBoundItem, DataRowView).Row)
Next