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.

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

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?

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

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

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

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.

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.

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);
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.