views:

706

answers:

3

Hello

I've been struggling with this for quite a while

My application contains a list view, populated with file-names, which are located on a server.

I'm trying to implement drag and drop functionality, so the user can drag files from my application into his/her's local computer.

In order to do this, first i'm downloading the files into a temporary location, and then calling my application's DoDragDrop() method.

The problem is that I want to perform the download process only after the DoDragDrop method is called.

I've tried every event related to drag drop methods (GiveFeedback, ItemDrag, etc...) but nothing works

so basically what I need is an event, raised after the DoDragDrop is done

any ideas??

A: 

Did you check DragDrop event? This is the event that raised on successful drop on your control.

Update: As long as you need to drad-n-drop your files to explorer with delayed rendering, you can read the following article (implementing native shell drag-n-drop in c#). Using information and code from this article you can create your own IDataObject implementation with delayed rendering support.

arbiter
No, I can't use this because i'm dragging **from** my control, not into it
Nissim
But drag-n-drop operation executed inside your application, or you drag into another app?
arbiter
From my application to another app (windows explorer, for this matter)
Nissim
+2  A: 

Not sure how to do this in .NET, but in regular Win32 programming, the object that implements the IDataObject interface can optionally implement the IAsyncOperation interface as well. The IDropTarget can then use that interface to perform the drag-n-drop in a background thread so that the source and target are not blocked during the actual transfer. The only gotcha is that the target, not the source, decides whether to take advantage of this or not.

The alternative is to use an "optimized move" transfer, where the IDataObject provides the filenames and the IDropTarget moves the files directly.

MSDN has details on that: Handling Shell Data Transfer Scenarios.

Of course, this still means you have to download the files before beginning the drag-n-drop. There really is no way to perform a drag-n-drop to determine the target and then perform the download afterwards. What you could do, though, is have the IDataObject hold CFSTR_FILEDESCRIPTOR and CFSTR_FILECONTENTS entries (described here: Shell Clipboard Formats), where the CFSTR_FILEDESCRIPTOR is filled in from information you used to populate your ListView, and the CFSTR_FILECONTENTS uses IStream interfaces whose implementations perform the download during the actual drop operation rather than prior to it. At least that way, you are only downloading the files that the target actually wants and can skip the rest.

Couple that with IAsyncOperation, and that may give you the final effect you are looking for.

Remy Lebeau - TeamB
Sounds great, only problem is that I have no clue how to translate it into C#.Any chance you can post a snippet (any programming language) and i'll try to translate it?Thanks
Nissim
(C++) you can also do what this guy said, and when(if) the drop occurs, BEFORE returning the IStream, download the file to a staging directory then return an IStream which copies it to the drop location
Dustin Getz
There is not much benefit to that when the IStream implementation can initiate the actual download when its Read() method is called for the first time, and just return data as it becomes available. Using a staging area just slows down how long the target has to wait for the file.
Remy Lebeau - TeamB
+1  A: 

Here is an example that may be similar to Remy's solution...

tbischel