473,465 Members | 1,946 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Drag and Drop to Windows Explorer

Hello,

How do I perform a drag and drop from a list view control to windows
explorer?

I am looking to perform a file copy from files in my list view to the
destination in the windows explorer program.

Thanks in advance
Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
www.callofcthulhu.com www.deadlandsgame.com
-
Nov 20 '05 #1
2 6223
Hi Simon,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to copy file to the
windows explorer by drop an item(usually the filepath string) from listview
to window explorer.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I think we can use the FileDrop DataFormat to do the job.

<Code Snippet>
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ListView1.AllowDrop = True
ListView1.View = View.Details
ListView1.Columns.Add("Column1", ListView1.Width - 4,
HorizontalAlignment.Left)
ListView1.Items.Add("C:\test.txt")
End Sub

Private Sub ListView1_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles ListView1.DragEnter
If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.All
Else
e.Effect = DragDropEffects.None
End If
End Sub

Private Sub ListView1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop
Dim s() As String = e.Data.GetData("FileDrop", False)
Dim i As Integer
For i = 0 To s.Length - 1
ListView1.Items.Add(s(i))
Next i
End Sub

Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
If ListView1.SelectedItems.Count > 0 Then
Dim strFilesPath() As String
ReDim strFilesPath(ListView1.SelectedItems.Count - 1)
For i As Integer = 0 To ListView1.SelectedItems.Count - 1
strFilesPath(i) = ListView1.SelectedItems(i).Text
Next
Dim dt As DataObject = New DataObject(DataFormats.FileDrop,
strFilesPath)
ListView1.DoDragDrop(dt, DragDropEffects.Copy)
End If
End Sub
</Code Snippet>

The code above is for demostration purpose, you may need to modify it to
adapt to your senario.
Please apply my suggestion above and let me know if it helps resolve your
problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 20 '05 #2
Thanks for your code snippet! Works a treat now! :-)

Many thanks,
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
www.callofcthulhu.com www.deadlandsgame.com
-
""Peter Huang"" <v-******@online.microsoft.com> wrote in message
news:2x**************@cpmsftngxa10.phx.gbl...
Hi Simon,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to copy file to the
windows explorer by drop an item(usually the filepath string) from
listview
to window explorer.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

I think we can use the FileDrop DataFormat to do the job.

<Code Snippet>
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ListView1.AllowDrop = True
ListView1.View = View.Details
ListView1.Columns.Add("Column1", ListView1.Width - 4,
HorizontalAlignment.Left)
ListView1.Items.Add("C:\test.txt")
End Sub

Private Sub ListView1_DragEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles ListView1.DragEnter
If (e.Data.GetDataPresent(DataFormats.FileDrop)) Then
e.Effect = DragDropEffects.All
Else
e.Effect = DragDropEffects.None
End If
End Sub

Private Sub ListView1_DragDrop(ByVal sender As Object, ByVal e As
System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop
Dim s() As String = e.Data.GetData("FileDrop", False)
Dim i As Integer
For i = 0 To s.Length - 1
ListView1.Items.Add(s(i))
Next i
End Sub

Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
If ListView1.SelectedItems.Count > 0 Then
Dim strFilesPath() As String
ReDim strFilesPath(ListView1.SelectedItems.Count - 1)
For i As Integer = 0 To ListView1.SelectedItems.Count - 1
strFilesPath(i) = ListView1.SelectedItems(i).Text
Next
Dim dt As DataObject = New DataObject(DataFormats.FileDrop,
strFilesPath)
ListView1.DoDragDrop(dt, DragDropEffects.Copy)
End If
End Sub
</Code Snippet>

The code above is for demostration purpose, you may need to modify it to
adapt to your senario.
Please apply my suggestion above and let me know if it helps resolve your
problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.

Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Colin Young | last post by:
I've got a owner-drawn listview control that displays images and now I'm trying to implement drag and drop so I can drag images from the control and drop them onto other applications. So far if I...
0
by: Lauren Quantrell | last post by:
I'm trying to drop a file from Windows Explorer (or desktop, etc.) onto a field in Access2K and capture the full file path. I found an posting below that says this is possible but I cannot...
5
by: Clyde | last post by:
I am trying to implement the user feedback provided by Windows Explorer when draggng a filename from one place to another. I have the drag and drop action worked out but have had no luck in...
4
by: Dave | last post by:
I need to add the ability to drag from a Windows Form and drop into a non dotNet application. For example, having a generated image in my app that I wish to drag out into explorer as a friendly way...
0
by: Yavuz Bogazci | last post by:
Hi, i have build a form with a listbox and the function that he user can drag and drop files from the windows explorer in this listbox. this works for me when i start it on my localmachine. ...
5
by: Brian Henry | last post by:
I haven't worked much with drag/drop but I am trying to make a form that accepts files to drug onto it from explorer and droped and have the form know the full path and file name of the files...
2
by: Robert Zahm | last post by:
I have created a C# user control which display certain filesystem information, and allows the user to drag an drop files into and out of the control. I then placed this user form in IE using an...
1
by: Sim | last post by:
Hello NG, I try to use drag and drop function between two list views. For this I found following code: ...
2
by: Andreas Mueller | last post by:
Hi All, I'm trying to show a context menu during a drag drop operation similar to the windows explorers right click drag and drop behavior (A full working sample is at the end of the post): ...
16
by: John | last post by:
I am looking for VBA code that will work with Access 2003 to enable dragging and dropping a file/folder name from Windows XP Explorer into an Access form's text box. This is a common functionality...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.