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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag & Drop First Time 3

Status
Not open for further replies.

alehawk

Programmer
Joined
Jun 18, 2003
Messages
332
Location
AR
Hi!
This is the first time that I need to use drag & drop.
I got a form with a textbox and a listbox. What I want to to is that when the user drags and drops one or more files to the form or listbox or textbox, my app gets the path & filenams of those files who were dragged and add it to the listbox.
How can I do that?
Tnx!!
 
Place a listbox on your form and set its OLEDropMode property to 1 (Manual).

Insert the following code in your form.
___
[tt]
Option Explicit
Private Sub List1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Data.GetFormat(vbCFFiles) Then
'List1.Clear
Dim N As Long
For N = 1 To Data.Files.Count
List1.AddItem Data.Files(N)
Next
End If
End Sub

Private Sub List1_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
If Data.GetFormat(vbCFFiles) Then
Effect = Effect And vbDropEffectCopy
Else
Effect = vbDropEffectNone
End If
End Sub[/tt]
___

Now run the program and drag-drop files from Windows Explorer or desktop.

You can use similar code to get the filenames in a textbox instead of a listbox.
 
than you!,than you!,than you!,than you!
 
welcome!,welcome!,welcome!,welcome!
[smile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top