Solved

OLEDragDrop/Data.Files Problem

Posted on 2006-11-03
15
870 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now