Solved

DataObject

Posted on 1998-07-26
6
757 Views
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
0
Comment
Question by:showme
  • 4
6 Comments
 

Author Comment

by:showme
ID: 1466754
Edited text of question
0
 

Author Comment

by:showme
ID: 1466755
Edited text of question
0
 
LVL 8

Expert Comment

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

0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:showme
ID: 1466757
Mike,
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
0
 
LVL 6

Accepted Solution

by:
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
        ListView1.OLEDrag
    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

0
 

Author Comment

by:showme
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
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

708 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

13 Experts available now in Live!

Get 1:1 Help Now