Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1350
ExpandAll performance
posted

Hello,

I need to expand a complete tree. Sometimes we have a lot of nodes with child nodes in that tree, e.g. 4000, and when I then call ExpandAll it takes quit a while.

The following example code demonstrates what I mean. The ExpandAll method needs 3.7sec on my machine. Is there any chance to speed it up? E.g. something like asynchronous ExpandAll ?

// ---- Populate the tree
tree.BeginUpdate();
tree.Nodes.Clear();

for(int i = 0; i < 200; i++) {
    UltraTreeNode rootNode = tree.Nodes.Add(i.ToString(), "Root_" + i.ToString());
    for(int j = 0; j < 10; j++) {
        UltraTreeNode subRootNode = rootNode.Nodes.Add(rootNode.Text + "_" + j.ToString());

        for(int k = 0; k < 5; k++) {
            UltraTreeNode subSubRootNode = subRootNode.Nodes.Add(subRootNode.Text + "_" + k.ToString());

            for(int l = 0; l < 10; l++) {
                UltraTreeNode child = subSubRootNode.Nodes.Add();
                child.Text = "Element " + l.ToString();
            }

        }

    }

}

tree.EndUpdate();

// ---- Expand all nodes
Stopwatch sw = new Stopwatch();
sw.Start();
tree.BeginUpdate();
tree.ExpandAll(); // Expand it
tree.EndUpdate();
sw.Stop();
MessageBox.Show(sw.Elapsed.TotalMilliseconds.ToString());

Thanks for the help?

Regards

Michael

Parents
No Data
Reply
  • 29085
    Suggested Answer
    Offline posted

    Hello Michael,

    I want to point out that your sample code above is built upon 100k nodes, not 4k. Nonetheless, a performance dip is to be expected with this node count. Do you require all your nodes to be added at once or can they loaded over time as they are made visible? If not you can use Load On Demand:

    http://es.infragistics.com/samples/windows-forms/tree/load-on-demand

    Let me know if you'd be interested implementing this or have any additional questions.

Children