检测到TreeView项上的DragDrop [英] Detecting a DragDrop onto a TreeView item

查看:110
本文介绍了检测到TreeView项上的DragDrop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从一个用户控件拖放到另一个TreeView。但是,如何检测到树状视图项目的下落?我可以检测到TreeView中是否有一个下拉列表,但是那不是该项目。我可以做一个TreeViewItem.Drop事件,但是那是当我将一个Item放到TreeView而不是从另一个控件中。

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.

我试图看到TreeView被聚焦,但是,这并没有解决。我可以在TreeView及其项目上检测到DragEnter / Leave,但无法检测到拖放。我看过其他主题,据说这些主题有一个DragOver可以解决此问题,但是那没用。

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.

推荐答案

试试看:

    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);
    }


注意:您必须具有的AllowDrop属性为TreeView设置为true。
而且,您必须处理此事件:

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;
}

这篇关于检测到TreeView项上的DragDrop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆