473,748 Members | 9,913 Online
Bytes | Software Development & Data Engineering Community
+ 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****@h eadfirst.co.uk
www.callofcthulhu.com www.deadlandsgame.com
-
Nov 20 '05 #1
2 6241
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(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
ListView1.Allow Drop = True
ListView1.View = View.Details
ListView1.Colum ns.Add("Column1 ", ListView1.Width - 4,
HorizontalAlign ment.Left)
ListView1.Items .Add("C:\test.t xt")
End Sub

Private Sub ListView1_DragE nter(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles ListView1.DragE nter
If (e.Data.GetData Present(DataFor mats.FileDrop)) Then
e.Effect = DragDropEffects .All
Else
e.Effect = DragDropEffects .None
End If
End Sub

Private Sub ListView1_DragD rop(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles ListView1.DragD rop
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_Mouse Down(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles ListView1.Mouse Down
If ListView1.Selec tedItems.Count > 0 Then
Dim strFilesPath() As String
ReDim strFilesPath(Li stView1.Selecte dItems.Count - 1)
For i As Integer = 0 To ListView1.Selec tedItems.Count - 1
strFilesPath(i) = ListView1.Selec tedItems(i).Tex t
Next
Dim dt As DataObject = New DataObject(Data Formats.FileDro p,
strFilesPath)
ListView1.DoDra gDrop(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****@h eadfirst.co.uk
www.callofcthulhu.com www.deadlandsgame.com
-
""Peter Huang"" <v-******@online.m icrosoft.com> wrote in message
news:2x******** ******@cpmsftng xa10.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(ByVa l sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Load
ListView1.Allow Drop = True
ListView1.View = View.Details
ListView1.Colum ns.Add("Column1 ", ListView1.Width - 4,
HorizontalAlign ment.Left)
ListView1.Items .Add("C:\test.t xt")
End Sub

Private Sub ListView1_DragE nter(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles ListView1.DragE nter
If (e.Data.GetData Present(DataFor mats.FileDrop)) Then
e.Effect = DragDropEffects .All
Else
e.Effect = DragDropEffects .None
End If
End Sub

Private Sub ListView1_DragD rop(ByVal sender As Object, ByVal e As
System.Windows. Forms.DragEvent Args) Handles ListView1.DragD rop
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_Mouse Down(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles ListView1.Mouse Down
If ListView1.Selec tedItems.Count > 0 Then
Dim strFilesPath() As String
ReDim strFilesPath(Li stView1.Selecte dItems.Count - 1)
For i As Integer = 0 To ListView1.Selec tedItems.Count - 1
strFilesPath(i) = ListView1.Selec tedItems(i).Tex t
Next
Dim dt As DataObject = New DataObject(Data Formats.FileDro p,
strFilesPath)
ListView1.DoDra gDrop(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
2649
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 drop on windows explorer it works (i.e. an image file is created where I dropped the image) or the console displays the full path to the image. Unfortunately it doesn't work with Excel. Nothing at all happens. No error, nothing. The code I am...
0
2604
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 simutate it. Can anyone help? Thanks ************************** previous post: Message 1 in thread
5
4967
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 finding how to capture the piece of the screen into a bitmap to simulate the movement. I know this could be done with the Windows API but can't find any way to do it with .Net functions. Any help is appreciated.
4
3067
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 to save it. I have tried creating the object that I place into the DoDragDrop() by inheriting the COM interfaces IDropSource and IDataObject with no luck. If anyone can help I am very much open to suggestions. Thanks in advance!
0
2864
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. But when i put my Apps .exe file on my WebServers WWWROOT directory and call it from the internet explorer. the application starts with the following error message.
5
10159
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 dropped onto it.. does anyone have any examples of this? thanks
2
2095
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 <object> tag. Doing this has broken the drag and drop functionality from Windows Explorer into IE (it still works fine going from IE to Windows Explorer). The problem is that whenever I drag a file over IE, IE wants to implement the drop...
1
5375
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: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchimpdragdrop.asp It works fine, but I have another problem. I want to create functionality like a Windows Explorer. This means, if I select some items from list view No 1 and drag&drop this to the list view No 2, then I want to mark automatically
2
5280
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): void treeView1_DragDrop(object sender, DragEventArgs e) { ContextMenu mnu = new ContextMenu(); mnu.MenuItems.Add("Click me", OnCmClick);
16
11843
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 that most Windows programs have, so I'm suprised it's not easier to implement in Access/VBA. Through Google, I found two VB6 examples and one VBA example on the Access Web written by Dev Ashish. The VB6 examples used loops to keep checking...
0
8987
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9534
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9366
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8239
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4597
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2777
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2211
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.