title: C# Treeview state expanded
body: <p>I have a treeview in my masterpage. When a contentpage is loaded i want to save the treeview state (which nodes are collapsed/expanded). I store the nodes in an ArrayList. Code:</p>
  
  <pre><code>private void SaveTreeviewState(TreeNodeCollection nodes)
  {
      foreach (TreeNode t in nodes)
      {
          // Store expandable state in ArrayList (true or false)
          //NodePaths.Add(t.Expanded);
          NodePaths.Add(t);
  
          // Check for childnods
          if (t.ChildNodes.Count &gt; 0)
              // recall this method
              SaveTreeviewState(t.ChildNodes);
  
      }
  }
  </code></pre>
  
  <p>This method is called by the unload event of the treeview object:</p>
  
  <pre><code>protected void tvManual_Unload(object sender, EventArgs e)
  {
      SaveTreeviewState(tvManual.Nodes);
  
      // Clear session
      Session["Treeview"] = null;
  
      // Add arraylistm to session
      Session["Treeview"] = NodePaths;
  
  }
  </code></pre>
  
  <p>In the load event of the masterpage i check whether my Session is set. When the session is set i call the method which read the session. </p>
  
  <p>The arraylist in the session contains all my nodes, so that's correct. However, all nodes have the property expended set to false. This isn't correct because i expanded mupliple nodes.</p>
  
  <p>Hope you guys understand my problem and can help me out.</p>
  
  <p>Thnx in advanced</p>