Reputation: 1116
I am doing a drag drop from one user control onto a different TreeView. However, how can I detect the drop into the tree view item? I can detect if there is a drop into the TreeView, but thats not the item. I can do an TreeViewItem.Drop event, but thats for when I drop an Item inside the TreeView, not from another control.
I tried seeing the TreeView to be focused, however, that did not solve it. I can detect DragEnter/Leave on the TreeView and it's Items, but not the drop. I have taken a look at other topics that said to have a DragOver to potentially fix this, hwever, but that did not work.
Upvotes: 0
Views: 2209
Reputation: 20620
Try this:
private void treeView1_DragDrop(object sender, DragEventArgs e)
{
Point DropXY = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
TreeNode DestinationNode = ((TreeView)sender).GetNodeAt(DropXY);
MessageBox.Show(DestinationNode.Text);
}
[EDIT] Note: You must have the AllowDrop property of the TreeView set to true. And, you must handle this event:
private void treeView1_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
Upvotes: 1