Drag Drop out of bounds

B

bob

Hi all,
I have a treeview that has drag drop.
Works well enough but...
If you drag out of bounds of the treeview the nodrop icon comes on.
Fair enough.
But when I move back inside the treeview the nodrop icon stays on and
essentially the action is cancelled when I release the mouse.
I would like to somehow 'retrieve' the drag action when the mouse
moves back inside the treeview to a legitimate drop point.
Any thoughts on how to do this would be appreciated.
thanks
Bob
 
M

Morten Wennevik [C# MVP]

bob said:
Hi all,
I have a treeview that has drag drop.
Works well enough but...
If you drag out of bounds of the treeview the nodrop icon comes on.
Fair enough.
But when I move back inside the treeview the nodrop icon stays on and
essentially the action is cancelled when I release the mouse.
I would like to somehow 'retrieve' the drag action when the mouse
moves back inside the treeview to a legitimate drop point.
Any thoughts on how to do this would be appreciated.
thanks
Bob

Hi Bob,

Are you in any way using QueryContinueDrag? The icons pretty much sort
themselves out with minimum calculation. If you only want to allow drop on
existing TreeNodes you can use the code below as a comparison, which
highlights the current node as well. The code does not filter data types or
effects in any way.

TreeNode lastNode = null;

void treeView1_DragOver(object sender, DragEventArgs e)
{
TreeNode currentNode =
treeView1.GetNodeAt(treeView1.PointToClient(MousePosition));

if (lastNode != null && lastNode != currentNode)
{
lastNode.BackColor = SystemColors.Window;
lastNode.ForeColor = SystemColors.ControlText;
}

lastNode = currentNode;

if (currentNode == null)
e.Effect = DragDropEffects.None;
else
{
currentNode.BackColor = SystemColors.Highlight;
currentNode.ForeColor = SystemColors.HighlightText;
e.Effect = DragDropEffects.All;
}
}

void treeView1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}

void treeView1_DragLeave(object sender, EventArgs e)
{
if (lastNode != null)
{
lastNode.BackColor = SystemColors.Window;
lastNode.ForeColor = SystemColors.ControlText;
}

lastNode = null;
}
 
B

bob

Hi Morten,
Thanks for your reply.
I realise I didn't give you the full story.
It is a scrollable treeview.
If the user is careful and just mouses up to the top or bottom edge of
the treeview. All is well it scroll and you can drop at the
appropriate place. If they barge over the treeview boundary then the
forbidden Icon appears. I want it to disappear when they come back in
bounds and allow them to continue on with the drag drop.
Thanks for the tip on using the QueryContinue drop event.
I put e.Action = DragAction.Continue; in the event handler but it
still insists on abandoning the dragDrop once you cross the border.
regards
Bob
 

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