Alex Prinias asked 2016-10-02 16:23:20 UTC
Hi guys,
In another thread, Tiago says that he is now able to drag'n drop between TreeView nodes, so I must be missing something... My implementation:
tv.AllowDrag = true;
tv.AllowDrop = true;
...........
void tv_ItemDrag(object sender, ItemDragEventArgs e)
{
TreeNode DragNode = (TreeNode)e.Item;
DoDragDrop(DragNode, DragDropEffects.Move);
}
void tv_DragDrop(object sender, DragEventArgs e)
{
TreeNode DragNode = (TreeNode)e.Data.GetData(typeof(TreeNode));
Point pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
TreeNode DestinationNode = tv.GetNodeAt(e.X, e.Y);
// dropping a node on itself is not allowed
if (DestinationNode != null && DestinationNode != DragNode)
{
..........................
}
}
First of all I don't find the tv.GetNodeAt(e.X, e.Y), which I need to get the drop target node. To make it compile, I tried as an alternative
TreeNode DestinationNode = (TreeNode)e.DropTarget; However, I haven't manages to initiate DragDrop, in my ItemDrag event I get an error saying "Cannot initiate dragging on MyTree when AllowDrag is false. But I have explicitly set that to true.
Any ideas?
Best,
Alex
Alex Prinias asked 2016-10-02 16:23:20 UTC
Hi guys,
In another thread, Tiago says that he is now able to drag'n drop between TreeView nodes, so I must be missing something... My implementation:
tv.AllowDrag = true;
tv.AllowDrop = true;
...........
void tv_ItemDrag(object sender, ItemDragEventArgs e)
{
TreeNode DragNode = (TreeNode)e.Item;
DoDragDrop(DragNode, DragDropEffects.Move);
}
void tv_DragDrop(object sender, DragEventArgs e)
{
TreeNode DragNode = (TreeNode)e.Data.GetData(typeof(TreeNode));
Point pt = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
TreeNode DestinationNode = tv.GetNodeAt(e.X, e.Y);
// dropping a node on itself is not allowed
if (DestinationNode != null && DestinationNode != DragNode)
{
..........................
}
}
First of all I don't find the tv.GetNodeAt(e.X, e.Y), which I need to get the drop target node. To make it compile, I tried as an alternative
TreeNode DestinationNode = (TreeNode)e.DropTarget; However, I haven't manages to initiate DragDrop, in my ItemDrag event I get an error saying "Cannot initiate dragging on MyTree when AllowDrag is false. But I have explicitly set that to true.
Any ideas?
Best,
Alex