Private Sub DataGridView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles DataGridView1.MouseDown
[COLOR=darkgreen] 'select mousedown row[/COLOR]
Dim hti As DataGridView.HitTestInfo = DataGridView1.HitTest(e.X, e.Y)
DataGridView1.Rows(hti.RowIndex).Selected = True
[COLOR=darkgreen] 'get data[/COLOR]
Dim obj As DataRowView = CType(DataGridView1.SelectedRows(0).DataBoundItem, System.Data.DataRowView)
[COLOR=darkgreen]'start dragdrop[/COLOR]
DataGridView1.DoDragDrop(obj, DragDropEffects.Copy)
End Sub
Private Sub DataGridView2_DragOver(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) _
Handles DataGridView2.DragOver
If e.Data.GetDataPresent(GetType(DataRowView)) = True Then e.Effect = DragDropEffects.Copy
End Sub
Private Sub DataGridView2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) _
Handles DataGridView2.DragDrop
If e.Data.GetDataPresent(GetType(DataRowView)) = True Then
If DataGridView2.Columns.Count = 0 Then [COLOR=darkgreen]'add columns[/COLOR]
For Each col As DataGridViewColumn In DataGridView1.Columns
DataGridView2.Columns.Add(col.Clone)
Next
End If
[COLOR=darkgreen]'get data[/COLOR]
Dim drow As DataRowView = e.Data.GetData(GetType(DataRowView))
[COLOR=darkgreen]'add row[/COLOR]
Dim ix As Integer = DataGridView2.Rows.Add
[COLOR=darkgreen]'add data items[/COLOR]
For Each col As DataGridViewColumn In DataGridView2.Columns
DataGridView2.Item(col.Name, ix).Value = drow.Item(col.Name).ToString
Next
End If
End Sub