
Treeview: Nodes.Clear method slower than removing one-by-one
This one has always kept me fairly happy:
With TreeView1.Nodes
' the loop is for multiple Root Nodes...
Do While .Count
Call .Remove(.Item(1).Root.Index)
Loop
End With
Among other things, the reason this is much faster is that if the
Node being Remove'd has descendent Nodes, before processing
the TVM_DELETEITEM message, the real treeview (that the VB
TreeView superclasses) first collapses the Node, removes all of
its descendent Nodes, and finally the Node itself, eliminating
potentially many unnecessary and time consuming tree redraws...
--
Brad Martinez, http://www.*-*-*.com/
Please direct questions/replies to the newsgroup
Quote:
>Thanks. Helps me too.
>If anyone finds a more elegant solution, please post it.
>By the way, I would definately classify this as a bug.
>Crazy Tim
>>-----Original Message-----
>>Hey! Really useful tip - thankyou!
>>I do like my splits to be{*filter*}ety.
>>Jonathan
>>> But if you set enable to false prior to the clear, it
>is{*filter*}ety split.
>in message
>>> > Just discovered this (well I thought it was
>interesting, anyway..)
>>> > clearing all nodes by using tv.Nodes.Clear is about
>20 times slower than
>>> > For i = tv.Nodes.Count to 1 step -1
>>> > tv.Nodes.Remove i
>>> > Next
>>> > I wonder why... (idle curiosity!)
>>> > Jonathan Gibbs
>>.