Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag and Dropping Files 1

Status
Not open for further replies.

yacyac

Programmer
Jul 29, 2002
78
US
I want to drag and drop a list of files from a VB6 listbox into another application. The other application accepts Drag and Drop from Windows Explorer (that is what I am trying to emulate).

My list box only lists the file name, however in a background array is the full filename. How would I go about doing this?

thanks in advance.
 
Drop a listbox on your form and try this code.
___
[tt]
Private Sub Form_Load()
FillFileList List1, "C:\"
End Sub
Sub FillFileList(LB As ListBox, ByVal Folder As String)
If Right$(Folder, 1) <> "\" Then Folder = Folder & "\"
Dim File As String
LB.Clear
File = Dir$(Folder & "*")
While Len(File)
LB.AddItem Folder & File
File = Dir$
Wend
End Sub
Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then List1.OLEDrag Else List1.Drag vbEndDrag
End Sub
Private Sub List1_OLEStartDrag(Data As DataObject, AllowedEffects As Long)
Dim N As Long
Data.Files.Clear
Data.SetData , vbCFFiles
For N = 0 To List1.ListCount - 1
Data.Files.Add List1.List(N)
Next
AllowedEffects = vbDropEffectCopy
End Sub[/tt]
 
Hypetia - I remembered you posted code a while ago to do something like this and I've been trying to find the thread to point yacyac to, glad to be beaten to the punch by the author of the code I was going to get him to look at [smile]

Harleyquinn

---------------------------------
For tsunami relief donations
 
I posted some code for making the listbox a drop target in thread222-967545 and thread222-746497.

One more example goes in thread222-516846.

This is the first time for posting code for making the listbox the source of drag-drop.

Thanks for remembering my posts.[smile]
 
Hypetia
Thanks for the quick response - it works heres a star for something that has been driving me nuts for some time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top