日期:2014-05-18  浏览次数:21398 次

[WinForm] TreeView节点的复制
请问如何实现

先在treeview选中某个节点A
点复制后
又选中同一树另一节点B
点粘贴
将A包括子节点复制到B节点
最好有相关的代码。或链接


谢谢,分不多了。解决马上结账

------解决方案--------------------

C# code
TreeNode td = (TreeNode)this.treeView1.SelectedNode.Clone();
this.treeView2.SelectedNode.Nodes.Add(td);

------解决方案--------------------
探讨


C# codeTreeNode td = (TreeNode)this.treeView1.SelectedNode.Clone();
this.treeView2.SelectedNode.Nodes.Add(td);




------解决方案--------------------
探讨
引用:


C# codeTreeNode td = (TreeNode)this.treeView1.SelectedNode.Clone();
this.treeView2.SelectedNode.Nodes.Add(td);





好快!

------解决方案--------------------
C# code

        TreeNode currentNode = null;
        TreeNode copyNode = null;
        bool canCopy = false;
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            currentNode  = e.Node;
        }

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys)Shortcut.CtrlC)
            {
                if (treeView1.Focused)
                {
                    copyNode = currentNode.Clone() as TreeNode;
                    canCopy = true;
                }
            }
            if (keyData == (Keys)Shortcut.CtrlV)
            {
                if (treeView1.Focused && canCopy)
                {
                    currentNode.Nodes.Add(copyNode);
                    canCopy = false;
                }
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }