I am interested in capturing a drag/drop event that will start with the user dragging an existing TreeNode somewhere within the TreeView. While the user is dragging the TreeNode around, I am interested in capturing when the node has been dragged between two tree nodes. When the user does this, I wanted to display a hash mark in-between the tree nodes to designate if the node would be dropped within the node as a child or as a sibling. This hash mark would display either: - underneath the destination node (to indicate the source node will be dropped as a child of the destination node OR - underneath the destination node to the left (to indicate the source node will be dropped as a sibling of the destination node), before or after...
I have made some headway using the DragOver event. I am calculating the mouse location and deriving what the top and bottom nodes are as I drag the mouse around..
int threshold = 8; //Joe(hack)
Point mouseLocation = mouseLocation = treeViewConditions.PointToClient(new Point(e.X, e.Y - threshold));
TreeNode topNode = treeViewConditions.GetNodeAt(mouseLocation);
mouseLocation = treeViewConditions.PointToClient(new Point(e.X + threshold, e.Y));
TreeNode bottomNode = treeViewConditions.GetNodeAt(mouseLocation);
if (topNode != null && bottomNode == null)
{
textBoxDescription.Text = "handling top node";
}
else if (topNode == null && bottomNode != null)
{
textBoxDescription.Text = "handling bottom node";
}
else if (topNode != null && bottomNode != null)
{
if (topNode != bottomNode)
{
textBoxDescription.Text = "between!";
}
else if (topNode == bottomNode)
{
}
}
However in doing this, it just feels dirty. I am wondering if anyone knew of a better way to do accomplish this.
Thanks a ton in advance!