Treeview Control - Performance - January 1998

We developed an application that uses the Microsoft Treeview control to ‘map’ conversion information from one data format to another. We call this function ‘Map Vendor Data’. Part of the screen:

Image18.gif

Creating the Tree was Very Slow

The function performed great in a test environment but was very slow in production. During testing we created 20 or 30 nodes. There are 300-500 nodes in the production system. After some trial and error testing we discovered that the way we had implemented the Expanded property was the culprit. We were using code similar to:

For i = 1 To iCount
    tree.Nodes.Add , , "K" & i, "MyText" & i
    tree.Nodes("K" & i).Expanded = True
Next

The Fix – An Order of Magnitude Faster

Removing the setting of the Expanded property from the creation loop and making a separate loop made a huge difference in performance. Tree creation went from 20-30 seconds to less than one second. The rewritten code is similar to:

For i = 1 To iCount
    tree.Nodes.Add , , "K" & i, "MyText" & i
Next
Dim nod As Node
For Each nod In tree.Nodes
    nod.Expanded = True
Next

Download As Word 97 Document

Click here to download this page as a zipped Word 97 Document [13k].

Previous Tip    Tip Index    Next Tip

Home

Updated 2000/10/29