MS ListView control and OLEDragDrop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • topher23
    Recognized Expert New Member
    • Oct 2008
    • 234

    MS ListView control and OLEDragDrop

    I've had a request for database functionality that I've never done before, and several hours of research have led me nowhere. Here's the skinny:

    My users would like to be able to drag a picture file from a digital camera onto a form and have it link to the record in the form.

    Research led me to the MS ListView control as a good Drag-And-Drop activator, but I can't get an OLEDragDrop event that will work. I used the example I found somewhere

    Code:
    Private Sub ControlName_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, Y As Single)    
    
        Dim sF As String
        Dim J As Integer
        
        For J = 1 To Data.Files.Count
            sF = sF & Data.Files(J) & vbCrLf
        Next
        MsgBox sF
        
    End Sub
    and I get

    "The expression you entered as the event property setting produced the following error: The procedure declaration does not match description of event procedure having the same name."

    If anyone has experience with this control, please give me some pointers! MSDN has been utterly useless on this subject.
    Last edited by topher23; Jan 13 '10, 12:56 AM. Reason: added all of the sample code
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    As this is a VB6 event you should also post this in Visual Basic. You might have better luck finding someone who is familiar with it. Unfortunately, I've never used it.

    I know it's stating the obvious but have you a reference to the VB6 library.

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Hello topher23:
      I wrote some code for you that will allow you to Drag-N-Drop either Single or Multiple Files from Windows Explorer into a ListView Control named ListView1. Once dropped, all of the File's Absolute Paths will be displayed within the context of the ListView Control under a single Column Header named Absolute File Path. The code has been thoroughly tested and is fully operational, any questions feel free to ask.
      Code:
      Private Sub ListView1_OLEDragDrop(Data As Object, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
      Dim varFileName As Variant
      
      'Create an object variable for the ColumnHeader object.
      Dim clmX As ColumnHeader
      
      'Create a variable to add ListItem objects.
      Dim itmX As ListItem
      
      'Add 1 Column Header. The width of the Column Header is the width
      'of the ListView Control.
      Set clmX = ListView1.ColumnHeaders.Add(, , "Absolute File Path", ListView1.Width)
      
      ListView1.BorderStyle = ccFixedSingle       'Set BorderStyle property.
      ListView1.View = lvwReport                  'Set View property to Report.
      ListView1.OLEDropMode = ccOLEDropManual     'Initiate DROP Operation
      
      If Data.GetFormat(ccCFFiles) Then
        For Each varFileName In Data.Files
          Set itmX = ListView1.ListItems.Add(, , varFileName)
        Next
      Else    'Data is not in the desired Format
          Effect = ccOLEDropEffectNone
      End If
      End Sub

      Comment

      • topher23
        Recognized Expert New Member
        • Oct 2008
        • 234

        #4
        Thanks, ADezii, that worked beautifully! It looks like the problem was that in VB6 the variable type for Data is MsComCtlLib.Dat aObject (or, on some of the examples I found, just DataObject) but in VBA it's just Object. When I change the Data variable back to DataObject in your code I get the same error.

        With any luck, this thread will be able to help others who also had no luck searching for a proper way to use the method in Access.

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Glad it worked out for you, topher23.

          Comment

          Working...