I have a treeview, tv, and a button on a form. In the button’s click event I have the following code:
var root = new TreeNode();
root.Text = “Root Node”;
for (int i = 1; i <= 5; i++)
var node = new TreeNode();
node.Text = “Node ” + i.ToString();
I would expect that every time I click the button I get the same treeview, since the first line of my code clears the treeview. However, a new “Root Node” is added every time, and the treeview keeps extending. Am I missing something?
To be honest I was suspecting they might be related, since after tv.Nodes.Clear() the count was zero but of course the treeview had all the previous nodes. But I wasn’t sure. After all it was easy to reproduce! 🙂
I think you found the issue I was referring to on https://wisej.com/support/question/treeview-wrong-node-count.