title: Copy all treeView parent and children to another treeView c# WinForms
body: <p>I am trying to copy the entire tree (exactly all nodes) of a treeview (completely) to another treeview using this code:</p>
  
  <pre><code>        TreeNodeCollection myTreeNodeCollection = treeView1.Nodes;
  
          TreeNode[] myTreeNodeArray = new TreeNode[treeView1.Nodes.Count];
  
          treeView1.Nodes.CopyTo(myTreeNodeArray, 0);
  
          treeView2.Nodes.AddRange(myTreeNodeArray);
  </code></pre>
  
  <p>But this does not allow me to do so, it asks to either delete the nodes in source treeview or use it Clone! How can I do that? I dont want my source treeview to lose anything in this process. </p>
  
  <p>** UPDATE **
  Ok guys I found a complicated code (for me!!) but how can I use this?</p>
  
  <pre><code>    public static T DeepTreeCopy&lt;T&gt;(T obj)
      {
          object result = null;
          using (var ms = new MemoryStream())
          {
              var formatter = new BinaryFormatter();
              formatter.Serialize(ms, obj);
              ms.Position = 0;
              result = (T)formatter.Deserialize(ms); ms.Close();
          }
          return (T)result;
      } 
  </code></pre>