Solved

Clearing TreeViews

Posted on 1998-10-21
10
239 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
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.

758 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

19 Experts available now in Live!

Get 1:1 Help Now