DragDrop event

  • Thread starter Michael Hutchinson
  • Start date
M

Michael Hutchinson

Is there any way to get the DragDrop event fire when DragDropEffects.None is
used? I'd like to restore the order of a Treeview after a failed
rearrangement.
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Michael,
Setting Effects property to DragDropEffects.None in DragEnter or DragOver
events is indication that you don't (can't) accept the data dragged. If you
don't accept the data you won't receive DragDrop event.
You will receive DragLeave event insted.

However, I believe that you should rearrange your treeview only if there is
a drop.
Let say you want to move a node on different place.
As a targed the threeview should add a new node in the right place in
response to DragDrop event and set Effects to *Copy* or *Move* according to
the AllowedEffects, keystates and/or any other conditions. As a source the
threevew should remove the original node if DoDragDrop returns *Move*. In
this case you don't have to do anything when the effect is set to *None*.
During DragEnter, DragOver and DragLeave you shold provide some feedback
which shouldn't do any real changes to the tree. Moving a bitmap with some
sketch of the data will do just fine.
 
M

Michael Hutchinson

Stoitcho Goutsev (100) said:
Hi Michael,
Setting Effects property to DragDropEffects.None in DragEnter or DragOver
events is indication that you don't (can't) accept the data dragged. If
you
don't accept the data you won't receive DragDrop event.
You will receive DragLeave event instead.



That DragLeave event was just what I was looking for. I should be able to
fix that up.
However, I believe that you should rearrange your treeview only if there
is
a drop.
Let say you want to move a node on different place.
As a targed the threeview should add a new node in the right place in
response to DragDrop event and set Effects to *Copy* or *Move* according
to
the AllowedEffects, keystates and/or any other conditions. As a source the
threevew should remove the original node if DoDragDrop returns *Move*. In
this case you don't have to do anything when the effect is set to *None*.
During DragEnter, DragOver and DragLeave you shold provide some feedback
which shouldn't do any real changes to the tree. Moving a bitmap with some
sketch of the data will do just fine.



It's a little more complicated than that. All dragging and dropping takes
place inside the TreeView, and nothing should go outside, as the only
purpose of the d+d is to rearrange nodes in a linked XML document. Left-drag
works as you would expect, but the idea with the right-drag is that it
actually changes the *order* of the nodes within the parent of the node
being dragged. So as you move the node upwards it swaps the nodes to
simulate the new position etc. I do not want the node move *into* anything,
I just want to change its Index. And I can't seen any way of representing it
moving *between* two nodes. If the right-drag fails, I want to restore the
old order.

I may change this feature to ctrl-left-drag, and use a context menu to allow
copying for right-drag, but the principle is the same.


Thanks for the help,



Michael Hutchinson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top