it-partners Home   |  Site Map
 Support
       Bits and Pieces

Drag and Drop rows

This code can be used to allow users to drag and drop rows within itGrid (unbound mode only).

Before using this code, ensure that you have specified an icon (cursor preferably) for the itGrid.DragIcon property. You can download and use DragMove.cur if you like.

It is also suggested that you use:

itGrid.SelectionMode = itSelectRow

Private m_lRow As Long

Option Explicit

Private Sub itGrid1_DragDrop(Source As Control, X As Single, Y As Single )

  If m_lRow >= itGrid1.FixedRows Then

    Dim lRow As Long
    Dim sRow As String

    With itGrid1

      lRow = .MouseRow

      If (lRow <> -1) And (lRow <> m_lRow) Then

        sRow = .TextMatrix(m_lRow, .FixedCols, m_lRow, (.Cols - 1))

        .Redraw = False

        .AddItem sRow, lRow
        If (lRow < m_lRow) Then
          .RemoveItem (m_lRow + 1)
        Else
          .RemoveItem m_lRow
        End If
        .SelectRange lRow, .MouseCol

        .Redraw = True

      End If

    End With

  End If

End Sub

Private Sub itGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single )

  m_lRow = itGrid1.MouseRow

  If m_lRow <> -1 Then
    ' The drag starts here
    itGrid1.Drag vbBeginDrag
  End If

End Sub

^ top