Solved

Vb code to drag multiple items from the MSFlexgrid

Posted on 2007-03-24
1
1,614 Views
Last Modified: 2013-11-25
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.
0
Comment
Question by:str_kani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 18827977
MSFlexGrid cant act as an normal DrgSource as you found.

I tried it using Right-mouse as the drag action..... it will trigger ok provided the target has OLEDropMode=manual

Non standard I know but it works.


see http://www.codeguru.com/forum/archive/index.php/t-8455.html for more discussion. He used a timer control to determine wether the Drag should enable which is probably more intuitive.


'--------------------------------

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim j As Integer, i As Integer
    Dim current_row As Integer, end_row As Integer
   
    If Button = vbRightButton Then
        If Me.MSFlexGrid1.RowSel > 0 And Me.MSFlexGrid1.Row > 0 Then
            j = 1
            current_row = Me.MSFlexGrid1.Row
            end_row = Me.MSFlexGrid1.RowSel
        End If
        MSFlexGrid1.OLEDrag                 ''''''''''''''''''''''''''  DRAG  ''''''''''''''''''''
    End If
End Sub


Private Sub MSFlexGrid1_OLEStartDrag(Data As MSFlexGridLib.DataObject, AllowedEffects As Long)
'http://www.codeguru.com/forum/archive/index.php/t-8455.html
   
    Dim sTmpStr As String
    Dim iVal As Integer
    Dim i As Integer
    '
    sTmpStr = ""
    '
    '


    With MSFlexGrid1
   
      'populate drag info
       mstrDragInfo = "test2"
       
    ' Build up the data to copy over to the other grid
    ' In this case, it's a tab-delimeted list of the selected row
       
        For i = .Col To .ColSel
            sTmpStr = sTmpStr & MSFlexGrid1.TextMatrix(.Row, i) & vbTab
        Next

        'set data - has to be set even if drag data comes from other sources!
        Data.SetData sTmpStr, vbCFText  'send the control name
       
        'set drop effect
        AllowedEffects = vbDropEffectCopy
       
    End With
End Sub


Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)

' get the data from the clipboard and copy it to the drop-flexgrid
'
    Text1.Text = ""
    If Data.GetFormat(vbCFText) = True Then
        Text1.Text = Data.GetData(vbCFText)
    End If
    MsgBox "DragDrop:"
End Sub

Private Sub Text1_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
    Text1.Text = "qwe"
End Sub


0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question