• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 786
  • Last Modified:

DataObject

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
showme
Asked:
showme
  • 4
1 Solution
 
showmeAuthor Commented:
Edited text of question
0
 
showmeAuthor Commented:
Edited text of question
0
 
MikeP090797Commented:
Try this:
Data.Files.Add listview.SelectedItem.Key
AllowedEffects = vbDropEffectCopy

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
showmeAuthor Commented:
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
 
anthonycCommented:
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
 
showmeAuthor Commented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now