Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Clearing TreeViews

Posted on 1998-10-21
10
Medium Priority
?
255 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 200 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
Industry Leaders: 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!

 
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
 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Screencast - Getting to Know the Pipeline
Suggested Courses

927 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