Connecting Tech Pros Worldwide Help | Site Map

Drag Drop out of bounds

bob
Guest
 
Posts: n/a
#1: Oct 22 '08
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
=?Utf-8?B?TW9ydGVuIFdlbm5ldmlrIFtDIyBNVlBd?=
Guest
 
Posts: n/a
#2: Oct 23 '08

re: Drag Drop out of bounds


"bob" wrote:
Quote:
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]
bob
Guest
 
Posts: n/a
#3: Oct 23 '08

re: Drag Drop out of bounds


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]
<MortenWennevik@hotmail.comwrote:
Quote:
>"bob" wrote:
>
Quote:
>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;
}
Closed Thread