loading treeview dynamically is very slow

C

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
 
R

Robinson

Bracket all adds with this:

myTreeView.BeginUpdate ()

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

myTreeView.EndUpdate ()
 
T

tommaso.gastaldi

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
 

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