Home All Groups Group Topic Archive Search About

loading treeview dynamically is very slow

Author
29 Nov 2006 7:53 PM
cowznofsky
Rather than load all my data into the treeview I am loading when a
level-1node gets expanded (for the first time).
To set up the code below, I've added a single child node for each
level-1node, just so that I can get the "+" and the capability to
expand.


So the first time I click on any level-1 node, it loads 30 child nodes.

The problem is how slow this is.  To me it should be almost
instantaneous.  It takes 2-3 seconds, which doesn't sound like much,
but believe me, it's irritating.  The scroll bar rolls down the screen.
Once the nodes are populated, expanding and collapsing the parent node
is suitably quick.

Any ideas on at least making this appear quicker?


----------------
Private Sub myTreeView_AfterExpand(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewEventArgs) Handles myTreeView.AfterExpand

        Dim classNode As TreeNode
        Dim testCtr As Integer

        If e.Node.Nodes.Count = 1 Then
            If e.Node.Text = e.Node.Nodes(0).Text Then
                e.Node.Nodes.Clear()
                For testCtr = 1 To 50
                    classNode = e.Node.Nodes.Add(testCtr.ToString)
                Next


            End If
        End If
    End Sub

Author
29 Nov 2006 9:00 PM
Robinson
Bracket all adds with this:

myTreeView.BeginUpdate ()

..............
..............

myTreeView.EndUpdate ()
Author
30 Nov 2006 3:20 PM
cowznofsky
Ah, much better.  Thanks!

Robinson wrote:
Show quoteHide quote
> Bracket all adds with this:
>
> myTreeView.BeginUpdate ()
>
> .............
> .............
>
> myTreeView.EndUpdate ()
Author
29 Nov 2006 11:06 PM
tommaso.gastaldi@uniroma1.it
cowznofsky ha scritto:

> Rather than load all my data into the treeview I am loading when a
> level-1node gets expanded (for the first time).
> To set up the code below, I've added a single child node for each
> level-1node, just so that I can get the "+" and the capability to
> expand.
>
>
> So the first time I click on any level-1 node, it loads 30 child nodes.
>
> The problem is how slow this is.

See if this improves (vb2005):

    Private Sub myTreeView_AfterExpand(ByVal sender As Object, _
                                       ByVal e As
System.Windows.Forms.TreeViewEventArgs) _
                                       Handles MyTreeView.AfterExpand

        Dim testCtr As Integer
        Dim SubNodes As New List(Of TreeNode)

        If e.Node.Nodes.Count = 1 Then
            If e.Node.Text = e.Node.Nodes(0).Text Then
                e.Node.Nodes.Clear()
                For testCtr = 1 To 50
                    SubNodes.Add(New TreeNode(testCtr.ToString))
                Next
                e.Node.Nodes.AddRange(SubNodes.ToArray)
            End If
        End If

    End Sub