TreeView performance

J

Joe

I'm loading a TreeView with ~8900 root nodes and only a couple of child
nodes giving a total of 8910 nodes.

It takes several seconds for the tree to display. The method that populates
the tree returns in < .5 seconds.

Populating the tree in the Load event takes even longer than clicking a
button after the screen has been loaded.

try
{
treeView1.BeginUpdate();

foreach (DataRow dr in mytable.Rows)
treeView1.Nodes.Add(dr[mycol].ToString());

}
finally
{
treeView.EndUpdate();
}

Is there an Allocate method or property I can call or set before loading to
possibly speed it up?
Another thing worth mentioning is that the screen also takes ~1.5 - 2
seconds to close when the tree is loaded.

If I don't load the tree the screen opens and closes immediately.
 
C

Carlos J. Quintero [.NET MVP]

IMHO, 8900 nodes are too many from the usability perspective, some previous
filtering should be required. If really that amount is needed, some common
controls support a technique called "Virtual XXX", based on owner-draw. Here
you have a sample of Virtual Listview to show what I mean:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcsample98/html/vcsmpvlistvw.asp

Maybe there is also a sample of virtual treeview in the MSDN Library, not
sure.

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
G

Grant Frisken

The standard TreeView (and most commercial) TreeView controls will have
real performance issues once you get start getting that many root
nodes. If have a large number of nodes spread fairly evenly you can
improve performance with the standard TreeView by loading the child
nodes when the user clicks the expand icon (you have to add a dummy
node first so that the expand icon is displayed).

If you are willing to consider a commercial solution then Infralution's
VirtualTree would provide the performance you are seeking. The tree
loads almost instantly regardles of the number of root nodes (or total
tree size) because it loads data on demand ie as it is required for the
current display.

You can find a fully functional demo at:

www.infralution.com/virtualtree.html

Regards
Grant Frisken
Infralution
 

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