1,105,386 Community Members

Drag and drop from windows forms to desktop and windows explorer

Member Avatar
murderotica
Junior Poster
171 posts since Aug 2008
Reputation Points: -3 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

Hello there, I've been having a hard time lately with implementing the drag and drop functionality outside the windows forms. I have no problem doing drag and drop within and between windows forms and from the desktop to the windows form. I have created an application where you can drag and drop any item on it. My problem is, I do not know how to implement the reverse of my application, to drag and drop from my app to the desktop or any destination outside my form. Any advise and ideas I will gratefully accept. Thank you.

Member Avatar
LizR
Posting Virtuoso
1,735 posts since Aug 2008
Reputation Points: 171 [?]
Q&As Helped to Solve: 190 [?]
Skill Endorsements: 4 [?]
 
0
 

google is your friend - a bit of resarch to find out what the desktop wants and will accept dropped onto it should help.

Member Avatar
murderotica
Junior Poster
171 posts since Aug 2008
Reputation Points: -3 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

I found a resource and tried it but it seems that when I try to drop my file to the desktop, nothing happens. I can drag it already but it cannot drop the file. Here's what I did:

private void listview_ItemDrag(object sender, ItemDragEventArgs e){
  DataObject object = new DataObject()
  string f = listview.SelectedItems[0].Text;
  object.SetData(DataFormats.FileDrop, f);
  DoDragDrop(object, DragDropEffects.All);
}

It can drag already but cannot drop. What do you think is the problem?

Member Avatar
murderotica
Junior Poster
171 posts since Aug 2008
Reputation Points: -3 [?]
Q&As Helped to Solve: 2 [?]
Skill Endorsements: 0 [?]
 
0
 

Maybe I need a RegisterDragDrop() function but it seems its not available in C#?

Member Avatar
exploree_123
Newbie Poster
1 post since Jun 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hi
i want to implement that u have implemented..drag and drop anywhere outside the form but using mouse events only no drag and drop events....
can u help me regarding this...........

thanks in advance

Member Avatar
it2051229
Junior Poster in Training
82 posts since May 2007
Reputation Points: -3 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

hmmm... the only way I can think of to do that one is that to play with the location of the object that is being dragged.. so let's say while you
're dragging your object the X and Y Coordinates is updated.. now when you release the mouse, you try to check the X and Y coordinates of the object and if it is outside the bounds of the FORM, then you assume that the object has been dragged out of the form and perform the necessary event...

i haven't done this yet but give it a try and tell me if it worked

Member Avatar
Diamonddrake
Master Poster
721 posts since Mar 2008
Reputation Points: 396 [?]
Q&As Helped to Solve: 92 [?]
Skill Endorsements: 8 [?]
 
-1
 

http://social.msdn.microsoft.com/forums/en-US/winforms/thread/68cc6e07-295d-4df2-b74f-0421a6378b47/

This information seems hand, for files, but just for sake of working code, there is a codeproject example that has a demo app with source code of how to drag a url shortcut to the desktop from you application found here

http://www.codeproject.com/KB/cs/draginternetshortcut.aspx

I wish I had more, I have been putting off working this out for a feature in an app I'm working on myself.

best of luck.

Member Avatar
starapple
Newbie Poster
2 posts since Feb 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

http://social.msdn.microsoft.com/forums/en-US/winforms/thread/68cc6e07-295d-4df2-b74f-0421a6378b47/

This information seems hand, for files, but just for sake of working code, there is a codeproject example that has a demo app with source code of how to drag a url shortcut to the desktop from you application found here

http://www.codeproject.com/KB/cs/draginternetshortcut.aspx

I wish I had more, I have been putting off working this out for a feature in an app I'm working on myself.

best of luck.

Did anybody solve this? It has to be possible because several existing applications have the feature to drag files to Explorer folders. Dragging is enabled but the file isn't moving or copying.

If you don't know the answer or aren't willing to help please don't suggest googling.

Member Avatar
dbirdz
Newbie Poster
1 post since Jan 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

hey I came across this thread with the same problem. however the solution working for me looks very much the same - at least I can find no real difference. I can select entries from my listview, and drag them onto the desktop, and there it creates a copy. (I do force a copy with the DragDropEffects, but it works also with DragDropEffects.All.)

here is my code:

private void lsvFiles_ItemDrag(object sender, ItemDragEventArgs e)
        {
            // Proceed with the drag-and-drop, passing the selected items for 
            string[] filepaths = new string[listview.SelectedItems.Count];
            int i = 0;
            foreach (ListViewItem item in listview.SelectedItems)
                filepaths[i++] = ((FileInfo)item.Tag).FullName;
            DataObject data = new DataObject(DataFormats.FileDrop, filepaths);
            data.SetData(DataFormats.StringFormat, filepaths);
            DoDragDrop(data, DragDropEffects.Copy);
        }
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article