Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

Clearing Treeview Content

I have about 3000 node in my treeview control. To clear this content I Use Clear method which takes a lot of time to clear it . How I can clear this content in faster way.
0
AHMKC1
Asked:
AHMKC1
  • 2
  • 2
  • 2
  • +3
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
display another empty treeview control instead, and clear the original one in the background.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
in the background means: use a timer control for example to clear the nodes by bunches of 10 for example.
this will look faster for the user, although in total time it will be slower...
0
 
fostejoCommented:
AHMKC1,

The TreeView is probably refreshing itself as it's being altered - you could try ..

a) disabling it before issuing the clear.
b) ensuring sorting is disabled
c) 'clearing' with another method such as actually deleting the items with 'item.delete' in a loop - that may turn out to be faster!

cheers
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
fostejoCommented:
AHMKC1,

Also (d) try setting 'Visible=false' so it's not shown at all on screen during the clear etc.

0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Disabling or changing visibility didn't seem to affect the time really.  Seems to be more of a memory management issue releasing all the nodes internally.

If you don't want to use the Timer approach, then the deleting in a loop idea seems to be the next best choice.

In my simple tests, deleting from the back was MUCH faster than deleting from the front:

Private Sub Command1_Click()
    Dim i As Integer
    Dim cnt As Integer
    cnt = TreeView1.Nodes.Count
    For i = cnt To 1 Step -1
        TreeView1.Nodes.Remove i
    Next
End Sub
0
 
BrianGEFF719Commented:
>>In my simple tests, deleting from the back was MUCH faster than deleting from the front:

I thought that TreeView stores the nodes as a 'double linked list', although I could be wrong, in that case it should make a difference whether you move from front->back or back->front with no time difference.


Brian
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Try it out for yourself!     =)

Posting your results (whether they confirm my results or not) is beneficial to all...
0
 
ddepastinoCommented:
I argue for Idle_Mind's results, if you remove the first item (index 1) the rest of the contents need to be "re-dimmed" so that the indexes start at 1 again.  By starting at the end you would just be dropping off the last item.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 2
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now