Clearing a Treeview

T

tiger79

Hi,
I've got a program which queries a database and makes a treestructure in a
Treeview with it results.
No want to be ablt to clear the treeview as fast as possible. I am using
TreeView.Node.Clear() right now, but when I got a lot of nodes (lets say
starting around 40 and more, and keep in mind I have to be able to make
structures existing out of 200 and more nodes) it takes like 3-4 seconds to
clear the TreeView AND it also behaves a little strange : the vertical
scrollbar keeps refreshing and changing size...
I'd like to know if it's possible to "reset" the TreeView or to cancel all
the nodes of level 1 in one time ?
 
P

Peter Foot [MVP]

You can turn off updates during the clear procedure and then re-enable them
afterwards, this will stop the control redrawing e.g.

treeView1.BeginUpdate()
treeView1.Nodes.Clear()
treeView1.EndUpdate()

Peter
 
T

tiger79

tried that allready but it won't make a difference...
cause while its doing it u dont see the nodes disspear or whatever but u
still see the vertical scrollbar which then starts to grow (obviuosly cause
there are less and less nodes)... problem is that it takes way too long in
my opinion...
So I guess there is no way to "reset" the treeview to a starting position
(empty that is) ?
 
T

tiger79

Ok, I found a way to make it way faster and it also doesnt make my program
crash anymore with too many nodes ;)

treeView1.BeginUpdate();

treeView1.CollapseAll();

treeView1.Nodes.Clear();

treeView1.EndUpdate();



this will work way better, maybe there is a better way, but i'm quite
satisfied for now... it takes about half of the time it took before, with
like 200 nodes it takes about 2 seconds instead of 4, which is just
acceptable...
 
T

tiger79

cause I want to place the new results in the same treeview... making another
one would also be a little messy programming in my eyes...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top