Reputation: 8982
I know that there is usually a DoDragDrop
method that starts a drag and drop operation. And that there are events (such as DragEnter
, DragOver
, DragDrop
, DragLeave
) that can be handled on the target side.
Are there any events on the source of the dragdrop that will tell me whether the dragdrop operation was completed, or possibly cancelled?
Upvotes: 5
Views: 2439
Reputation: 2398
You are referring to a situation similar to delete-on-paste in Windows Explorer where a file is not deleted from the source folder until a Paste operation occurs.
http://msdn.microsoft.com/en-us/library/bb776904(VS.85).aspx#delete_on_paste
If you are doing this within the same instance of the application, then this is referred to an optimized move where you can simply set a local flag (such as a boolean variable) to determine if it was successful.
Update: Yes, you can also check the results of the DoDragDrop method to determine if the drop was successful. Just make sure that your drop-handling code properly sets the Effect to None if there was an error completing the drop, or else your code with DoDragDrop will think that the drop was a success. This method will even work between two instances of your application.
If you are doing this between two instances of your application, and you need to transfer more information that just whether or not the drop was successful, then you need to implement the OLE version of IDataObject
so that the application instance that is the drop target completes the drag and drop, it can call SetData on the source object to send result information. This is complicated to do but is certainly possible.
For more information on doing this, see these links:
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.comtypes.idataobject.aspx
Upvotes: 1
Reputation: 941397
Yes, DoDragDrop() has a return value. It returns DragDropEffects.None if the drop was cancelled.
Upvotes: 7