By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,402 Members | 1,091 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,402 IT Pros & Developers. It's quick & easy.

Dragging a file from Windows into My program

P: n/a
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

Jan 31 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Pam,

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

http://www.microsoft.com/downloads/d...displaylang=en

Probably is in that all you ask.

I hope this helps,

Cor
Jan 31 '06 #2

P: n/a
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:
Pam,

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

http://www.microsoft.com/downloads/d...displaylang=en

Probably is in that all you ask.

I hope this helps,

Cor


Jan 31 '06 #3

P: n/a
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:
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).

<pa***********@libero.it> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.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


Feb 1 '06 #4

P: n/a
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).

<pa***********@libero.it> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.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

Feb 1 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.