Solved

DataObject

Posted on 1998-07-26
6
760 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
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…

932 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

11 Experts available now in Live!

Get 1:1 Help Now