Link to home
Start Free TrialLog in
Avatar of Kani Str
Kani StrFlag for India

asked on

Vb code to drag multiple items from the MSFlexgrid

I have a Treeview control and MSFlexgrid in my VB application. The records in the grid will be displayed based on the folder selected in the treeview. Now i want to drag multiple items from the grid and drop those into a folder in the treeview so that the items from one folder will be moved to the dropped folder. I have done it. I have written the drag event in the Mousedown event of MSFlexgrid

My problem is, i cannot select the multiple items in the grid with the mouse but i can do so by using shift key and mouse left button. This is because the drag event is written in Mousedown event of the grid.

My code in Mousedown event of MSFlexgrid is, (VB code)
drag_listingsids is the variable that stores the id of each row in the grid.

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
If frmmain.MSFlexGrid1.RowSel > 0 And frmmain.MSFlexGrid1.row > 0 Then
    j = 1
    current_row = frmmain.MSFlexGrid1.row
    end_row = frmmain.MSFlexGrid1.RowSel
    If frmmain.MSFlexGrid1.row <= frmmain.MSFlexGrid1.RowSel Then
        For i = frmmain.MSFlexGrid1.row To frmmain.MSFlexGrid1.RowSel
            If drag_listingids = "" Then
                drag_listingids = MSFlexGrid1.TextMatrix(i, 0)
            Else
                drag_listingids = drag_listingids & "," & MSFlexGrid1.TextMatrix(i, 0)
            End If
        Next
    ElseIf frmmain.MSFlexGrid1.row > frmmain.MSFlexGrid1.RowSel Then
        For i = frmmain.MSFlexGrid1.RowSel To frmmain.MSFlexGrid1.row
            If drag_listingids = "" Then
                drag_listingids = MSFlexGrid1.TextMatrix(i, 0)
            Else
                drag_listingids = drag_listingids & "," & MSFlexGrid1.TextMatrix(i, 0)
            End If
        Next
    End If
End If
MSFlexGrid1.OLEDrag                   ''''''''''''''''''''''''''  DRAG  ''''''''''''''''''''
End If
End Sub


In short what i want to do is, select multiple items in the grid using mouse, drag them and drop them into the treeview folder.
ASKER CERTIFIED SOLUTION
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial