日期:2014-05-17  浏览次数:20951 次

请问怎么在两个treeview之间移动节点啊。。
要包括子节点的父节点啊

------解决方案--------------------
这个很容易,首先窗体的allowdrag设置为true,控件也要。
然后treeview1 treeview2 同样设置为true
        private TreeNode exchangenode = null;
        private void treeView1_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = e.AllowedEffect;
            if (e.Data.GetDataPresent(typeof(System.Windows.Forms.TreeNode)))
            {
                e.Effect = DragDropEffects.Copy;
                exchangenode = (TreeNode)e.Data.GetData(typeof(System.Windows.Forms.TreeNode));
            }
            else
                e.Effect = DragDropEffects.None;
        }
        private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)
        {
            DoDragDrop(e.Item, DragDropEffects.Copy);
        }

        private void treeView1_DragLeave(object sender, EventArgs e)
        {
            if (exchangenode != null)
            {
                treeView1.Nodes.Remove(exchangenode);
            }
        }

        private void treeView2_DragEnter(object sender, DragEventArgs e)
        {
            e.Effect = e.AllowedEffect;
            if (e.Data.GetDataPresent(typeof(System.Windows.Forms.TreeNode)))
                treeView2.Nodes.Add((TreeNode)e.Data.GetData(typeof(System.Windows.Forms.TreeNode)));
        }

------解决方案--------------------
DragDrop,ItemDrag,DragEnter,DragLeave事件