TreeView performance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe

    TreeView performance

    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.Begin Update();

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

    }
    finally
    {
    treeView.EndUpd ate();
    }

    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.


  • Carlos J. Quintero [.NET MVP]

    #2
    Re: TreeView performance

    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:



    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:
    MZ-Tools has a single goal: To make your everyday programming life easier. As an add-in to several Integrated Development Environment (IDEs) from Microsoft, MZ-Tools adds new menus and toolbars to them that provide many new productivity features.



    "Joe" <J_no_spam@_no_ spam_Fishinbrai n.com> escribió en el mensaje
    news:e8hP413ZFH A.3132@TK2MSFTN GP09.phx.gbl...[color=blue]
    > 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.Begin Update();
    >
    > foreach (DataRow dr in mytable.Rows)
    > treeView1.Nodes .Add(dr[mycol].ToString());
    >
    > }
    > finally
    > {
    > treeView.EndUpd ate();
    > }
    >
    > 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.
    >
    >[/color]


    Comment

    • Grant Frisken

      #3
      Re: TreeView performance

      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:



      Regards
      Grant Frisken
      Infralution


      Joe wrote:[color=blue]
      > 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.Begin Update();
      >
      > foreach (DataRow dr in mytable.Rows)
      > treeView1.Nodes .Add(dr[mycol].ToString());
      >
      > }
      > finally
      > {
      > treeView.EndUpd ate();
      > }
      >
      > 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.[/color]

      Comment

      Working...