How to Prevent Flicker when Updating ListView (ANSWER)

How to Prevent Flicker when Updating ListView (ANSWER)

Post by Charles La » Sun, 27 Mar 2005 22:05:21


Ok chaps. I have the answer.

It would seem that I had mis-read the purpose of the BeginUpdate/EndUpdate
methods; like many before me I suspect.

These commands actually make the update occur, thus causing the flicker not
reducing it.

I tried all sorts of things, from double-buffering to sub-classing and
filtering the WM_ERASEBKGND message. I even tried LockWindowUpdate from one
of our esteemed number from way back. None of these worked.

The answer is as simple as calling the Update method after adding each item.

<code>
With ListView1
Dim lvi As New ListViewItem("Some really important information")

lvi.ForeColor = Color.Green

.Items.Add(lvi)

.EnsureVisible(.Items.Count - 1)

.Update()
End With
</code>

The result is a silky smooth update, with no flicker. No sub-classing,
filtering, or double-buffering required.

Can you tell I'm happy :-))

Charles