Ver Mensaje Individual
  #2 (permalink)  
Antiguo 19/10/2009, 03:26
kyha
 
Fecha de Ingreso: junio-2008
Ubicación: Valencia
Mensajes: 152
Antigüedad: 15 años, 10 meses
Puntos: 3
Respuesta: mover o arrastrar una fila en un datagridview

1º Propiedad AllowDrop del datagridView = true

2º Evento DrapDorg del DatagridView
Código vb.net:
Ver original
  1. ' The mouse locations are relative to the screen, so they must be
  2.         ' converted to client coordinates.
  3.         Dim clientPoint As Point = grid2.PointToClient(New Point(e.X, e.Y))
  4.         ' Get the row index of the item the mouse is below.
  5.         filaLugarnuevo = grid2.HitTest(clientPoint.X, clientPoint.Y).RowIndex
  6.  
  7.         'Comprobamos que los indices de las filas no son el mismo y que no es el anterior a la fila seleccionada
  8.             If filaLugarnuevo <> filaSeleccionada Then
  9.                 If (filaLugarnuevo + 1) <> filaSeleccionada Then
  10.                     'Comprobamos que el efecto sea el de mover una fila
  11.                     If (e.Effect = DragDropEffects.Move) Then              
  12.                        'Aqui pondremos si queremos guardar los datos en una BD

3ºEvento MouseMove del DatagridView
Código vb.net:
Ver original
  1. If e.Button = Windows.Forms.MouseButtons.Left Then
  2.             If filaSeleccionada <> -1 Then
  3.                 If dragBoxFromMouseDown <> Rectangle.Empty And Not dragBoxFromMouseDown.Contains(e.X, e.Y) Then
  4.  
  5.                     ' Iniciamos el porcedimiento de arratrar.                    
  6.                     Dim dropEffect As DragDropEffects
  7.                     dropEffect = grid2.DoDragDrop(grid2.Rows(filaSeleccionada), DragDropEffects.Move)
  8.                 End If
  9.             End If
  10.         End If

Creo que no me olvido de nada.

Espero te sirva.