"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]