C# Drag and Drop functionality
I'm trying to achieve functionality similar to winzip/winrar, etc. I have a Treeview
that displays the contents of a package (System.IO.Packaging). I want to be able to drag and drop a file or folder from the TreeView
onto an explorer window or the desktop, etc. My problem is that I have to call DoDragDrop
before I know if the object was actually even dropped. That means to create the DataObject
with the FileDrop
type, I must extract those contents of the package out to a temporary area and then provide that path to the DataObject before calling DoDragDrop
. If the user doesn't drop on a capable container or cancels the drop, the overhead of extracting those contents is wasted. I've noticed that winzip does not actually create the temporary file until the drop occurs on a valid target. I've checked the DataFormats provided by the WinZip drop and they are normal FileDrop, FileNameW, FileName and Shell IDList Array. The first three simply hold a string to the temporary location that winzip extracted that file to. I'm not sure what the last one does.
Long story short, I want to be able to avoid extracting the contents until I know the drop location was valid. Is there a callback to figure out the drop location? Any suggestions would be extremely helpful.
System.Windows.DragDropEffects de开发者_高级运维 = DragDrop.DoDragDrop(treeview1, dataObj, System.Windows.DragDropEffects.Move);
I've tried this with an application similar to an FTP server - I wanted to start downloading only after the user actually dropped the item. Unfortunately I found no way to do this using managed code only.
The way WinZip probably does it is by receiving COM callbacks (please forgive me if I'm using the wrong words here) and you'd have to create a managed wrapper around the native COM object in order to receive such callbacks yourself.
It's certainly possible, but I gave up and embedded a FolderTreeView thingie in my application to catch the drop events myself :/
精彩评论