Pages

Thursday, February 12, 2009

Flickering ListView

If you have a ListView in a Windows Forms app, use the following code to stop it from flickering:

using System.Reflection;

// For some reason the "DoubleBuffered" property isn't exposed on the ListView class
// so we have to use reflection to set it even though it's a "protected" property...

PropertyInfo oDoubleBuffered = this.listView1.GetType().GetProperty(
"DoubleBuffered", BindingFlags.NonPublic | BindingFlags.Instance );
if ( oDoubleBuffered != null )
oDoubleBuffered.SetValue( this.listView1, true, null );

No comments:

Post a Comment