"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 QueryContinueDr ag? 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_DragO ver(object sender, DragEventArgs e)
{
TreeNode currentNode =
treeView1.GetNo deAt(treeView1. PointToClient(M ousePosition));
if (lastNode != null && lastNode != currentNode)
{
lastNode.BackCo lor = SystemColors.Wi ndow;
lastNode.ForeCo lor = SystemColors.Co ntrolText;
}
lastNode = currentNode;
if (currentNode == null)
e.Effect = DragDropEffects .None;
else
{
currentNode.Bac kColor = SystemColors.Hi ghlight;
currentNode.For eColor = SystemColors.Hi ghlightText;
e.Effect = DragDropEffects .All;
}
}
void treeView1_DragE nter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects .All;
}
void treeView1_DragL eave(object sender, EventArgs e)
{
if (lastNode != null)
{
lastNode.BackCo lor = SystemColors.Wi ndow;
lastNode.ForeCo lor = SystemColors.Co ntrolText;
}
lastNode = null;
}
--
Happy Coding!
Morten Wennevik [C# MVP]