drag and drop from Explorer to TreeView in VB.net

W

Wanda

Hello,

I am trying to drag a file from Explorer to the TreeView control in
VB.Net, but I have no idea how this will work, could I get the lines
of code on how I can accomplish this please?

Thanks in advance, any help would greatly appreicate.
Wanda
 
J

Jay B. Harlow [MVP - Outlook]

Wanda,
You can use the DragDrop event of the Tree View to accept the
DataFormats.FileDrop format to get a list of file names (an array of string)
dragged from Windows Explorer.

If Clipboard.GetDataPresent(DataFormats.FileDrop) Then
' Get list of files
Dim files As String()
files = DirectCast(Clipboard.GetData(DataFormats.FileDrop),
String())
' process each file in the list.
End If


See:
System.Windows.Forms.DataFormats - FileDrop
System.Windows.Forms.IDataObject
System.Windows.Forms.Control - DragDrop, DragEnter, DragLeave, DragOver

Chapter 24 of "Programming Microsoft windows with Microsoft Visual Basic
..NET" by Charles Petzold from MS Press has an example of how to accept these
events and open a file.

Hope this helps
Jay
 
W

Wanda

Thanks...

I can do drag and drop files now, but how about dragging a message or
an attachment from MS Outlook to treeview, how can I do it in that
case? I know Window Explorer have this feature which allow drag and
drop email and attachement from Outlook...If Treeview is not the
appropriate control, what built in VB controls should I use?


Thanks in advace. I would greatly appreciated for any help
Wanda
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top