[SOLVED] TreeView Nodes Clear

Answered Closed
0
0

Hi guys,

I have a treeview, tv,  and a button on  a form. In the button’s click event I have the following code:

tv.Nodes.Clear();
var root = new TreeNode();
root.Text = “Root Node”;
tv.Nodes.Add(root);

for (int i = 1; i <= 5; i++)
{
var node = new TreeNode();
node.Text = “Node ” + i.ToString();
root.Nodes.Add(node);
}

tv.ExpandAll();

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?

Best,
Alex

 

  • You must to post comments
Best Answer
0
0

Hi Alex & Tiago,

build 1.2.71 is now available including a fix for WJ-7669.

Can you guys please retest your applications ? Thanks !

Best regards
Frank

  • You must to post comments
0
0

Hi Frank,

All good with Nodes.Clear() now! Thanks.

Alex

  • You must to post comments
0
0

Hi Tiago,

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! 🙂

Thanks Tiago!

Alex

  • You must to post comments
0
0

Hi Alex,

I think you found the issue I was referring to on https://wisej.com/support/question/treeview-wrong-node-count.

Thanks 🙂

  • You must to post comments
0
0

Hi Alex,

I could reproduce the problem and logged WJ-7669 for it.

Best regards
Frank

  • You must to post comments
Showing 5 results