问题将节点添加到树视图 [英] Problem with adding nodes to a treeview

查看:100
本文介绍了问题将节点添加到树视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图从一个树视图复制到另一个节点,我得到了一个奇怪的错误:不能添加或插入在多个地方的项目节点1,您必须首先从当前位置删除或克隆它
参数名:节点
搜索一段时间后,我找不到任何解决方案。我在VB.NET尝试这样做,有同样的错误
码例如:

When I was trying to copy node from one treeview to another, I got a strange error: "Cannot add or insert the item 'node1' in more than one place. You must first remove it from its current location or clone it. Parameter name: node" After searching for a while, I couldn't find any solution. I tried this in VB.NET and had the same error Code example:

TreeNode node1 = new TreeNode("node1");
node1.Name = "node1";
treeView1.Nodes.Add(node1);
TreeNode nd = treeView1.Nodes[0];
treeView2.Nodes.Add(nd);



有没有这方面的任何解决方案?



谢谢大家!这工作了!

Are there any solutions for this?


Thanks everyone! This works now!

推荐答案

是,使用深层副本

TreeNode nd = (TreeNode )treeView1.Nodes[0].Clone();



你的代码改成这样

change your code to this

TreeNode node1 = new TreeNode("node1");
node1.Name = "node1";
treeView1.Nodes.Add(node1);
TreeNode nd = (TreeNode )treeView1.Nodes[0].Clone(); // clone the object
treeView2.Nodes.Add(nd);

这篇关于问题将节点添加到树视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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