Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview Slow to Clear Nodes

Status
Not open for further replies.

MattSTech

Programmer
Apr 10, 2003
333
0
0
US
I am not seeing this as a discussion topic which leads me to believe I am the only one who has this problem. When using a Treeview control, you clear it using the .Nodes.Clear Method. For some reason when I use this method with a latge amount of data in the control, the control hangs for a short period while it erases the contents of the control.
I am using the following loop to clear the control instead and it works quite a bit faster. Any thoughts on why I am seeing this?

Code:
For i = tvwList.Nodes.Count To 1 Step -1
    tvwList.Nodes.Remove (i)
Next
vs.

Code:
tvwList.Nodes.Clear
 
Ick. Even worse than I thought.
If I don't scroll the control, it clears quickly. If I scroll to the bottom it takes forever (3 sec or so) to clear even with my loop.

I decided to make the control invisible, clear it, then make it visible again. It clears instantly now regardless of scroll position. Must be a refresh thing??
 
Try using the LockWindowUpdate API function which enables/disables drawing in a specific window.

You should call [tt]LockWindowUpdate tvwList.hWnd[/tt] before clearing the treeview and [tt]LockWindowUpdate 0[/tt] after the treeview is clear to re-enable drawing.

It will improve performance in both cases.
 
>Try using the LockWindowUpdate

And read the documentation in the link provided, and then use WM_SETREDRAW instead ... (IMHO)
 
Good read strongm. I did not see the documentation in detail. In fact, I never got a chance to use this function myself. Never needed so.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top