468,291 Members | 1,489 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,291 developers. It's quick & easy.

Drag Drop out of bounds

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
Oct 22 '08 #1
2 3108
"bob" wrote:
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(MouseP osition));

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;
}
--
Happy Coding!
Morten Wennevik [C# MVP]
Oct 23 '08 #2
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
On Wed, 22 Oct 2008 23:13:00 -0700, Morten Wennevik [C# MVP]
<Mo************@hotmail.comwrote:
>"bob" wrote:
>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(Mouse Position));

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;
}
Oct 23 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by SamSpade | last post: by
4 posts views Thread by Qingdong Z. | last post: by
14 posts views Thread by Nathan | last post: by
1 post views Thread by Kevin L | last post: by
reply views Thread by SamSpade | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.