drag and drop from Explorer to TreeView in VB.net

  • Thread starter Thread starter Wanda
  • Start date Start date
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
 
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
 
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
 
Back
Top