Solved

Clearing TreeViews

Posted on 1998-10-21
10
242 Views
Last Modified: 2010-05-18
Hi all.

Is there a quicker way of clearing a treeview than using TTreeView.Items.Clear???  I have 870 items in the view and it takes for ever to clear (on a P266).  Im using it to display search results.

Cheers!

Stu.
0
Comment
Question by:Stuart_Johnson
10 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 total points
ID: 1343817
Use LockWindowUpdate to stop the treeview redrawing while its clearing.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1343818
Just a quick question... Is this how I do it?

LockWindowUpdate(ListView1.Handle);
ListView1.Items.Clear;
LockWindowUpdate(0);

Do I need to specify the last line?  

Stuart.
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1343819
Yes you need to otherwise it won't be unlocked.... The code above is right...

Cheers,
Viktor
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1343820
Thanks guys!  Much appreciated
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1343821
Hi Guys, me again :)

I just tried at out on the application here (I asked the question at work and the program is at home) and it is still too slow.  Its taking around 5-10 seconds to clear the TreeView.

It really has to be quicker than that.  I am hoping for a refresh time of less than a second.

Is there an API I can use to clear it?  Or is my only hope disposing of the TreeView and creating another one?

Thanks for the info if you can provide it.

Stuart.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:rwilson032697
ID: 1343822
You could try destroying it and creating another one as you suggest.

Another (sneaky) way might be to have 2 or more treeviews. You fill one up, then user does another search so you swap the full one to the back and fill up the one on top. In the OnIdle event you could kill a few of the elements at a time to eventually empty it and make it available again.

This is fairly much overkill though. Just killing the control should be tons easier!
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1343823
Mmm..  I dont really like the idea of doing that.  There is too much code attached to it to just delete it.   That was a last resort solution.

Surely there is a way of clearing it quickly. M$ does it with the Explorer.

Stu.
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 1343824
I think part of the reason it can be slow is that Delphi is having to kill large numbers of huge strings. There are some TTreeView derived classes on DSP - one of those might have a fast clear method.

http://sunsite.icm.edu.pl/delphi
0
 

Expert Comment

by:5214305
ID: 1343825
Tree.Items.BeginUpdate;
Tree.Items.Clear;
Tree.Items.EndUpdate;

That's pretty fast and doesn't require any API call.
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1343826
5214305

Your "comment" actually worked the best.  The list is clear quicker than the blink of an eye.  Could you email me at jonstu@acay.com.au and I'll set up a dummy question for you.  You definately deserve some points for that one!

Stu.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now