Slow Mass TreeNode Text Update.

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!";
}
}
 
Ö

Özden Irmak

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top