title: ASP.NET Treeview control always appending nodes to CheckedNodes list
body: <p>I have an ASP.NET treeview on my page. In my codebehind I have the following method:</p>
  
  <pre><code>public string GetSelectedTreeValues(TreeView tv)
      {
          string taxVal = string.Empty;
  
          StringBuilder textBuilder = new StringBuilder();
          string lists = string.Empty;
          string cleanedlists = string.Empty;
  
          try
          {
              TreeNodeCollection checkedNodes = tv.CheckedNodes;
              foreach (TreeNode tn in checkedNodes)
              {
                  lists = textBuilder.Append(tn.ValuePath + ",").ToString();
              }
  
              // removing any trailing commas
              cleanedlists = lists.Substring(0, lists.Trim().Length - 1);
          }
          catch (Exception ex)
          {
              new ApplicationException("Error: Getting Tree Nodes", ex);
          }
          return cleanedlists;
      }
  </code></pre>
  
  <p>The problem is when I do a postback, if I change the values I've selected, they always <em>append</em> to the list of values. I thought the list of values should <em>clear</em>, then reset to the new values.</p>
  
  <p>I've stepped through the code and found the CheckedNodes property is always appending the nodes I check to the list without removing unchecked nodes.</p>