public class ben:harrell

October 7, 2006

TreeView Render Speed

Filed under: .NET, Technology — benjamin harrell @ 10:15 pm

Here is a quick tip when doing large updates and adds to the Windows Forms Treeview control. Use the beginupdate() method to “turn off” rendering and then after your changes are complete use the endupdate() method to turn rendering back on which will then render all of your changes.

Sometimes it is necessary to do this for a control that doesn’t have these wonderful methods but no to worry you can easily derive a control, add your own “flag” variable and then just override the OnPaint method and if your variable is set to not render then simply return from OnPaint. I have also added the Begin and EndUpdate methods below for setting the variable. If you want to force the control to repaint then you can call EndUpdate( true ). Here is a sample :

public class FastDrawTreeView : System.Windows.Forms.TreeView
private bool _disableRendering = false;

public void BeginUpdate()
_disableRendering = true;

public void EndUpdate(bool redraw)
_disableRendering = false;
if (redraw)

protected override void OnPaint(PaintEventArgs e)
if (_disableRendering)


Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: