Posted on 1998-07-26
Last Modified: 2012-06-21
I have a listview control which displays all the files in a selected directory (very much like the Window's Explorer).  I would like to add OLE drag functionality to this control but I am not sure how to do this.  Ideally, I would like to use, in the OLEStartDrag event,  

Data.SetData listview.SelectedItem.Key, vbCFFiles

since each item's key represents the path and name of the files.  However, when I do this I receive an error message or the like.  From the help file, I assume that this has something to do with a bstr variable(?) and the vbCFFiles format.  Since I am new to VB, I am not sure what this is all about and how to specify the vbCFFiles format with the data that I have.  If anyone knows how to do this and solve my OLE drag problem, please let me know.  More points await.

Thanks in advance, showme
Question by:showme
  • 4

Author Comment

ID: 1466754
Edited text of question

Author Comment

ID: 1466755
Edited text of question

Expert Comment

ID: 1466756
Try this:
Data.Files.Add listview.SelectedItem.Key
AllowedEffects = vbDropEffectCopy

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.


Author Comment

ID: 1466757
I tried the code you submitted but I received an error number 5 from the common controls DLL when I started to drag.  Let me know if there is another way.  

Thanks again, showme

Accepted Solution

anthonyc earned 200 total points
ID: 1466758
here is a small example that works..  Place a listview and a textbox on your form, and set the textbox's OLEDROPMODE to Manual.

Option Explicit

Private Sub Form_Load()
    ListView1.ListItems.Add , "c:\winnt\notepad.exe", "c:\winnt\notepad.exe"
End Sub

Private Sub ListView1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button And vbLeftButton And (Not ListView1.SelectedItem Is Nothing) Then
    End If
End Sub

Private Sub ListView1_OLEStartDrag(Data As ComctlLib.DataObject, AllowedEffects As Long)
    Data.Files.Add ListView1.SelectedItem.Key
    Data.SetData , vbCFFiles
    AllowedEffects = 3

End Sub

Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
    Text1.Text = Data.Files(1)
End Sub


Author Comment

ID: 1466759
Tried the code and it worked fine.  Thanks, Anthony!  If you have the chance can you explain why your code worked and the other didn't?  Does it have something to do with the line;

Data.SetData , vbCFFiles

Thanks again, showme

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

813 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

18 Experts available now in Live!

Get 1:1 Help Now