Drag and drop PDF files in VB 6.0

30 pts.
Tags:
PDF
PDF Files
Visual Basic 6
Hi there...! Is it possible to drag and drop pdf files using filelistbox and dirlistbox within vb6 form? Any comments will be appreciated... Thanks!

Software/Hardware used:
vb6

Answer Wiki

Thanks. We'll let you know when a new response is added.

Certain VB6 controls have “automatic” drag/drop capability. Textbox, Filelistbox & Dirlistbox support OLE drag drop properties.

BTW: Carlosdl could run rings around me on this stuff. I just happen to keep a copy of VB6 Unleashed around & looked it up for you. How to actually use them? Wouldn’t have a clue.

Gary

—–

Thanks Gary for mentioning the OLE drag option.

I had not played with it and decided to give it a try, and it actually simplifies the implementation of the drag and drop functionality a lot, but in this case, it does not automatically copy (or move) the files when the source and/or target of the dragging operation are file lists, so you have to actually copy the files by code, but that is pretty easy.

So, I guess the answer would be: It is not done automatically by the controls, but it can be implemented very easily using the OLE drag-drop properties and methods.

Here is a simplified example. Just create a form with two sets of DriveListBox,DirListBox and FileListBox (one of them will be the source of the drag and drop operations, and the other one will be the target).

Then, copy and paste this code:

<pre>Option Explicit

Private Sub Dir1_Change()
‘Sets the file list path
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
On Error GoTo error_handler
‘Sets the dir path
Dir1.Path = Drive1.Drive
Exit Sub
error_handler:
MsgBox Err.Description, vbCritical
End Sub

Private Sub Form_Load()
‘show Pdf files
File1.Pattern = “*.pdf”
File2.Pattern = “*.pdf”
End Sub

Private Sub Drive2_Change()
On Error GoTo error_handler
‘Sets the dir path
Dir2.Path = Drive2.Drive
Exit Sub
error_handler:
MsgBox Err.Description, vbCritical
End Sub
Private Sub Dir2_Change()
‘sets the file path
File2.Path = Dir2.Path
End Sub

Private Sub File2_OLEDragDrop(Data As DataObject, _
Effect As Long, Button As Integer, Shift As Integer, _
X As Single, Y As Single)
‘Copy the file from the source dir to the target dir
If Data.GetFormat(vbCFFiles) Then
FileCopy Data.Files(1), Replace$(Data.Files(1), Dir1.Path, Dir2.Path)
End If
End Sub
</pre>

-CarlosDL

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    I don't think so. They are just special types of list boxes. You would probably need to create the drag and drop functionality by yourself.
    70,220 pointsBadges:
    report
  • DoneThat
    Nice CarlosDL. I'm filing this for myself too. Love to learn new techniques. Jamjam18: Let us know how you made out.
    830 pointsBadges:
    report
  • Jamjam18
    [...] 1. Carlosdl and DoneThat provide some insight into dragging and dropping PDF files in Visual Basic 6.0. [...]
    0 pointsBadges:
    report
  • Jamjam18
    [...] 3. Carlosdl and DoneThat combine forces on a question about dragging and dropping PDF files in Visual Basic 6.0. [...]
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following