Link to home
Start Free TrialLog in
Avatar of Stuart_Johnson
Stuart_Johnson

asked on

Clearing TreeViews

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.
ASKER CERTIFIED SOLUTION
Avatar of rwilson032697
rwilson032697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stuart_Johnson
Stuart_Johnson

ASKER

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.
Yes you need to otherwise it won't be unlocked.... The code above is right...

Cheers,
Viktor
Thanks guys!  Much appreciated
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.
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!
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.
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
Tree.Items.BeginUpdate;
Tree.Items.Clear;
Tree.Items.EndUpdate;

That's pretty fast and doesn't require any API call.
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.