title: How to Drag And Drop selected rows between DataGridViews
body: <p>I need to implement drag and drop of the selected rows from one grid to the other:</p>
  
  <p>my code:</p>
  
  <p>datagridview1</p>
  
  <pre><code>Private Sub datagridview1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles datagridview1.MouseDown
  
      Dim info As DataGridView.HitTestInfo = Me.datagridview1.HitTest(e.X, e.Y)
  
      If info.Type = DataGridViewHitTestType.Cell And e.Button = Windows.Forms.MouseButtons.Left Then
  
          Me.datagridview1.DoDragDrop(datagridview1.SelectedRows.Cast(Of DataGridViewRow).OrderBy(Function(r) r.Index).ToArray, DragDropEffects.All)
  
      End If
  
  End Sub
  </code></pre>
  
  <p>datagridview2</p>
  
  <pre><code>Private Sub datagridview2_DragEnter(sender As Object, e As DragEventArgs) Handles datagridview2.DragEnter
  
      e.Effect = DragDropEffects.All
  End Sub
  
  Private Sub datagridview2_DragDrop(sender As Object, e As DragEventArgs) Handles datagridview2.DragDrop
  
      Try
          Dim Rows() As DataGridViewRow = DirectCast(e.Data.GetData(GetType(DataGridViewRow())), DataGridViewRow())
  
          For Each row As DataGridViewRow In rows
  
              MsgBox(row.Cells("ID").Value)
  
  
          Next
      Catch ex As Exception
  
      End Try
  
  End Sub
  </code></pre>
  
  <p>but there is an error in conversion.
  any ideas?</p>