c# - Error in Copy one node with its children in Treeview to another treeview -


i creating new treeview , want copy of other nodes it. have following error:

cannot add or insert item '' in more 1 place. must first remove current location or clone it.

my code as:

first_treeview.nodes.clear(); //treeview2.nodes.clear(); int length_last = treeview1.nodes[0].nodes.count; (int ii = 0; ii < length_last - 1; ii++) {     treenode temp_node = treeview1.nodes[0].nodes[ii];     first_treeview.nodes.add(temp_node); } 

and xml file:

<?xml version="1.0" encoding="utf-8"?> <component version="11"> <config /> <protect>     <this>         <user ="mike"/>     </this> </protect>   <actions>     <action name="test">         <obj name="system">                      </obj>     </action> </actions> </component> 

the error message says 1 node cannot belong 2 treeviews. have clone before adding first_treeview.

first_treeview.nodes.add((treenode) temp_node.clone()); 

Comments