1º Propiedad
AllowDrop del datagridView =
true
2º Evento
DrapDorg del DatagridView
Código vb.net:
Ver original' The mouse locations are relative to the screen, so they must be
' converted to client coordinates.
Dim clientPoint As Point = grid2.PointToClient(New Point(e.X, e.Y))
' Get the row index of the item the mouse is below.
filaLugarnuevo = grid2.HitTest(clientPoint.X, clientPoint.Y).RowIndex
'Comprobamos que los indices de las filas no son el mismo y que no es el anterior a la fila seleccionada
If filaLugarnuevo <> filaSeleccionada Then
If (filaLugarnuevo + 1) <> filaSeleccionada Then
'Comprobamos que el efecto sea el de mover una fila
If (e.Effect = DragDropEffects.Move) Then
'Aqui pondremos si queremos guardar los datos en una BD
3ºEvento
MouseMove del DatagridView
Código vb.net:
Ver originalIf e.Button = Windows.Forms.MouseButtons.Left Then
If filaSeleccionada <> -1 Then
If dragBoxFromMouseDown <> Rectangle.Empty And Not dragBoxFromMouseDown.Contains(e.X, e.Y) Then
' Iniciamos el porcedimiento de arratrar.
Dim dropEffect As DragDropEffects
dropEffect = grid2.DoDragDrop(grid2.Rows(filaSeleccionada), DragDropEffects.Move)
End If
End If
End If
Creo que no me olvido de nada.
Espero te sirva.