views:

363

answers:

4

It seems to me there is no way to detect whether a drag operation was successful or not, but there must be some way. Suppose that I want to perform a "move" from the source to the destination. If the user releases the mouse over some app or control that cannot accept the drop, how can I tell?

For that matter, how can I tell when the drag is completed at all?

I saw this question, but his solution does not work for me, and e.Action is always Continue.

+3  A: 

I'm not sure if that can help you, but DoDragDrop method returns final DragDropEffects value.

var ret = DoDragDrop( ... );
if(ret == DragDropEffects.None) //not successfull
else // etc.
cz_dl
A: 

Ah, I think I've got it. Turns out the call to DoDragDrop is actually synchronous (how lame), and returns a value of DragDropEffects, which is set to None if the op fails. So basically this means the app (or at least the UI thread) will be frozen for so long as the user is in the middle of a drag. That does not seem a very elegant solution to me.

Ok cz_dl I see you just posted that very thing so I'll give u the answer.

This I don't understand though: how can the destination determine whether the op should be a move or a copy? Shouldn't that be up to the source app?

chaiguy
A: 

How come the DoDragDrop() is synchronous, while your methods are still running inside your process if you have another control on the same form that accepts that dragged object

its OnDragOver, OnDragEnter, OnDragLeave, and OnDragDrop events will be executed asynchronosly.

I think its something in the MessageLoop that the .Net Framework provides for your application, but I dont know the actual trick.

however I will try the return value from the DoDragDrop, because I'm developing extensive drag drop in my current project and didn't think it could work that way,

thanks for the TIP ;)

Code Guru
A: 

Can't add comment yet, so another answer. I was also surprised when I saw for the first time, that DoDragDrop is called synchronously and it somehow doesn't froze the UI.

But the copy/move stuff I believe is perfectly logical. You can specify allowed effects while calling DoDragDrop method in source app and that's all what's important to you. How destination app will handle and use the data it's up to it.

cz_dl