title: How to avoid duplicate value in TreeView?
body: <p>I'm looking for a powerful and easy way to avoid duplicate values in a TreeView, now I perform the insertion in this way:</p>
  
  <pre><code>while (rdr.Read())
  {
       checkExists(rdr.GetString(3));
       rootNode.Items.Add(new TreeViewItem() { Header = rdr.GetString(3) });
  }
  </code></pre>
  
  <p>where RDR is a player that contains all the values to be added recursively. Now if these values have already been added, I would get duplicate values, so I created a function checkExists you should check if the value is already in the TreeView. I have not found solutions for WPF and I'm still learning how to use this control, I'd know how to do this.</p>
  
  <pre><code>public void checkExists(string campionato) 
  {
        foreach (TreeView node in nation_team)
        {
             if (NodeExists(node, campionato))
             exists = true;
        }
  }
  </code></pre>
  
  <p>This method is not ready, it's just a beta.     </p>
  
  <pre><code>private bool NodeExists(TreeNode node, string key) {
          foreach (TreeNode subNode in node.Nodes) {
              if (subNode.Text == key) {
                  return true;
              }
              if (node.Nodes.Count &gt; 0) {
                  NodeExists(node, key);
              }
          }
          return false;
      }
  </code></pre>
  
  <p>Possible solution that I've tried, in the foreach I'm trying to iterate through the all nodes, but the compiler tell me about GetEnumerator</p>