Dragging a file from Windows into My program

  • Thread starter Thread starter pamelafluente
  • Start date Start date
P

pamelafluente

Hi guys, I have a little question (hope it's not dumb) ;-)

I have a form, containing a TreeView, say TreeView1, I want to to add a
file to the tree:

Sub AddFile(ByVal MyFile As System.IO.FileInfo)
Dim t As New TreeNode(MyFile.Name)
Me.TreeView1.Nodes.Add(t)
End Sub

and I want to have the File (File Name / FileInfo, I guess would both
be fine) from a drag drop done from Windows Explorer (or in general
from a Windows dialog).

Could you, please, show me how to attach an handler to TreeView1 in
order to get the file from the drag drop.

Thank you very much in advance.

-Pam
 
Hi Cor Thank you very much for your help.

I have downloaded and taken a look at
"VB.NET How-To Create an Explorer-Style Application"

It's a very simple application which does this:

"ExplorerStyleViewer is, as the name implies, a simpler version of the
Windows Explorer application. ExplorerStyleViewer makes known more file
information than DirectoryScanner, demonstrates how to associate icons
with file types, and allows the user to run an application associated
with the file type (if an association exists) by double-clicking the
file (just like in Windows Explorer)"

doesn't do any drag drop....

Thank you anyway Cor ! . It's useful to know about those samples.

-Pam

Cor Ligthert [MVP] ha scritto:
 
Set the AllowDrop property of the control to True.

In the control's DragDrop event do something like:

If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim sFilesAry() As String = CType(e.Data.GetData(DataFormats.FileDrop),
String())

For i As Integer = 0 To sFilesAry.Length - 1
'do something
Next i
End If

Also you can use the DragEnter/DragOver events to inspect the data and
change the mouse pointer displayed to the user (for instance, e.Effect =
DragDropEffects.Link).
 
Thanks you Cmm. I just tried it.
I can't believe! it does work and it's so simple!!

You guys are just fantastic!!

THANKS!!!

-Pam



CMM ha scritto:
 

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

Back
Top