Search code examples
c#winformslistviewflickerownerdrawn

Flickering in ListView control (OwnerDraw, Virtual)


This question might be considered a follow-up to Flickering in listview with ownerdraw and virtualmode.

I've got a ListView control in Virtual mode and I attempt to perform custom drawing. Item rendering is done via the following method override:

protected override void OnDrawItem(DrawListViewItemEventArgs eventArgs) 

As mentioned in the referenced question, custom drawing introduces flickering on mouse over events. Debugger tells me this happens due to an excessive amount of custom draw events which are fired.


Now - the accepted answer to the referenced question tells us:

This is a bug in .NET's ListView and you cannot get around it by double buffering.

  • So, how reliable is that information? Is that really a bug? Or maybe we simply attempt to cut off a part of the messages and hope that it won't alter the visible behavior?

  • Is this true that if I have my owner drawing routine for the ListView in Virtual Mode, I can suppress these Custom Draw events and only perform my drawing in WM_PAINT or, maybe, this is incorrect for some cases?

  • What are the prerequisities for the System.Windows.Forms control to be able to do all the painting in WM_PAINT without altering it's initial behavior?


Solution

  • I've seen this flickering issue with ListView control in any custom rendering event handlers (DrawItem, DrawSubItem). I tried BeginUpdate()/EndUpdate() and double buffering with no success. I think .NET triggers additional WM_PAINT to all columns to the right of the custom drawn column.

    However I found this workaround to a single custom rendered column ListView. It works just fine!

    1. In the columnheader editor, set the custom drawn column as the last column
    2. Change the "DisplayIndex" of the position you want

    This should solve the flickering in mouseover or run-time rendering.