c# - 从一个Treeview拖放到另一个Treeview - WinForms

时间:2016-09-06 08:05:47

标签: c# winforms treeview

对于我的树视图(treeV和treeV_IgnoreD),我有以下DragAndDrop事件:

 private void treeV_IgnoredDragDropEvent(object sender, DragEventArgs e)
    {
        // Retrieve the client coordinates of the drop location.
        Point targetPoint = treeV_Ignored.PointToClient(new Point(e.X, e.Y));

        // Retrieve the node at the drop location.
        TreeNode targetNode = treeV.GetNodeAt(targetPoint);

        // Retrieve the node that was dragged.
        TreeNode draggedNode = (TreeNode)e.Data.GetData(typeof(TreeNode));

        // Confirm that the node at the drop location is not 
        // the dragged node and that target node isn't null
        // (for example if you drag outside the control)
        if (!draggedNode.Equals(targetNode) && targetNode != null)
        {
            // Remove the node from its current 
            // location and add it to the node at the drop location.
            draggedNode.Remove();
            targetNode.Nodes.Add(draggedNode);

            // Expand the node at the location 
            // to show the dropped node.
            targetNode.Expand();

        }
    }

    private void treeV_Ignored_ItemDrag(object sender, ItemDragEventArgs e)
    {
        DoDragDrop(e.Item, DragDropEffects.Move);
        MessageBox.Show("ola");
    }

    private void treeV_Ignored_DragEnter(object sender, DragEventArgs e)
    {
        e.Effect = DragDropEffects.Move;
    }

这些树视图从Oracle数据集中填充,并表示相同的数据。

我希望能够从“treeV”拖动项目,并将其放在“treeV_Ignored”中。

我该如何实现这种行为?

1 个答案:

答案 0 :(得分:1)

您的要求已完全填写link 请仔细研究。
此外,您必须首先理解,此处SplitContainer用于拖放目的,我们可以将树视图添加到此控件,因此我们可以轻松地将任何节点拖动到另一个树。如果您有任何问题,请告诉我