Solved

OLEDragDrop/Data.Files Problem

Posted on 2006-11-03
15
882 Views
Last Modified: 2008-01-09
I have "On Error Resume Next" in my ListView's OLEDragDrop sub but whenever I try to drag a bunch of files from the desktop including the recycle bin, nothing is added to the list.

Here's my code:

Private Sub lvwFiles_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, Y As Single)
On Error Resume Next
Dim i As Long
For i = 1 To Data.Files.Count
If IsFolder(Data.Files(i)) = True Or IsFile(Data.Files(i)) = True Then
lvwFiles.ListItems.Add , , Data.Files(i)
End If
Next
End Sub
0
Comment
Question by:orangutang
  • 8
  • 7
15 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17873514
Try...

Private Sub lvwFiles_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Data.GetFormat(vbCFFiles) Then
        Dim sText As String
        Dim i As Integer
        For i = 1 To Data.Files.Count
            lvwFiles.ListItems.Add , , Data.Files(i)
        Next
    End If
End Sub
0
 
LVL 22

Author Comment

by:orangutang
ID: 17874967
No, it still doesn't work.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17875051
Are you even getting into the event properly?

    Private Sub lvwFiles_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
        If Data.GetFormat(vbCFFiles) Then
            Dim i As Integer
            For i = 1 To Data.Files.Count
               MsgBox Data.Files(i)
            Next
        End If
    End Sub

Did you set the DropMode?

    Private Sub Form_Load()
        lvwFiles.OLEDropMode = 1 ' Manual
    End Sub
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
LVL 22

Author Comment

by:orangutang
ID: 17875065
It won't let me use "Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single"
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17876635
You're not using VB6 are you?

Are you using VBA in Word or Excel?
0
 
LVL 22

Author Comment

by:orangutang
ID: 17877058
No, I'm using VB6
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17877187
Hmm...ok.  The ListView dragdrop signature is different than the Form signature.

This works for me:

Option Explicit

Private Sub Form_Load()
    lvwFiles.OLEDropMode = 1 ' Manual
    lvwFiles.View = lvwSmallIcon
End Sub

Private Sub lvwFiles_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Data.GetFormat(vbCFFiles) Then
        Dim i As Integer
        For i = 1 To Data.Files.Count
            lvwFiles.ListItems.Add , , Data.Files(i)
        Next
    End If
End Sub
0
 
LVL 22

Author Comment

by:orangutang
ID: 17877482
But if you accidentally drop the recycle bin with the other files into the listview, all of the files except for the recycle bin are added?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17878298
Let me test it out...

On my system (WinXP Pro SP2), dragging the recycle bin did nothing.
0
 
LVL 22

Author Comment

by:orangutang
ID: 17882050
But the rest of the files are added?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17907865
(With my last code submission...)

Are you not getting any files at all?

Or is it just the recycle bin that you are worried about.  I can't add the Recycle Bin myself...but why would you want to anyways?...it is not an actual folder.
0
 
LVL 22

Author Comment

by:orangutang
ID: 17910337
I know but it's really bothering me why it doesn't add anything at all.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17910371
Regular files aren't getting added?

...or nothing gets added when the recycle bin is dropped?

The recycle bin is not an actual file...
0
 
LVL 22

Author Comment

by:orangutang
ID: 17910408
Nothing is added. I know the recycle bin isn't an actual file but I accidentally dragged it into the ListView and now it's driving me crazy that I can't get it to work if I drag the recycle bin into the list.
0
 
LVL 22

Author Comment

by:orangutang
ID: 17997861
I guess no one knows the solution. Oh, well. Thanks, anyway
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

789 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