Home All Groups Group Topic Archive Search About

Dragging a file from Windows into My program

Author
31 Jan 2006 6:14 PM
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

Author
31 Jan 2006 7:21 PM
Cor Ligthert [MVP]
Pam,

In the 101 samples for VB 2003 is a sample
How to create an explorer style Application.

http://www.microsoft.com/downloads/details.aspx?FamilyId=08E3D5F8-033D-420B-A3B1-3074505C03F3&displaylang=en

Probably is in that all you ask.

I hope this helps,

Cor
Author
31 Jan 2006 8:24 PM
pamelafluente
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:

Show quoteHide quote
> Pam,
>
> In the 101 samples for VB 2003 is a sample
> How to create an explorer style Application.
>
> http://www.microsoft.com/downloads/details.aspx?FamilyId=08E3D5F8-033D-420B-A3B1-3074505C03F3&displaylang=en
>
> Probably is in that all you ask.
>
> I hope this helps,
>
> Cor
Author
31 Jan 2006 10:48 PM
CMM
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).

<pamelaflue***@libero.it> wrote in message
Show quoteHide quote
news:1138731281.001215.175910@g47g2000cwa.googlegroups.com...
> 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
>
Author
1 Feb 2006 12:25 AM
pamelafluente
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:

Show quoteHide quote
> 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).
>
> <pamelaflue***@libero.it> wrote in message
> news:1138731281.001215.175910@g47g2000cwa.googlegroups.com...
> > 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
> >