Slow Mass TreeNode Text Update.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello, All,

I have a Windows Forms TreeView with about 1500 nodes. It takes only a
second to initially populate and display the TreeView with those 1500 nodes,
but if I want to mass update the Text property of all the nodes, it takes
almost 50 seconds!

The following code changes the Text property recursively, but I also
flattened the code into a while loop and it still took 50 seconds. I've
wrapped the method with a SuspendLayout / ResumeLayout. I've wrapped the
method by hiding the TreeView then displaying it when it's done. Still 50
seconds.

Does anyone have any idea why it takes so long to update the Text property
of 1500 TreeNodes? Thank you.

void UpdateTreeNodeTextRecursive( TreeNodeCollection nodes )
{
foreach (TreeNode loNode in nodes)
{
if (loNode.Nodes.Count > 0)
{
UpdateTreeNodeTextRecursive( loNode.Nodes );
}

loNode.Text = "Hello World!";
}
}
 
Hi,

Use BeginUpdate() before call your recursive function and EndUpdate() after
it, this should suspend the drawing of treeview while you're updating it...

Regards,

Özden
 
Yup, sometimes the answer is right in front of your nose, and you want to
kick yourself once you see it.

Thank you for the solution to my problem.

Kind Regards,
Eric
 
Back
Top