All I want is to update an ListViewItem’s text whithout seeing any flickering.
This is my code for updating (called several times):
listView.BeginUpdate(); listViewItem.SubItems[0].Text = state.ToString(); // update the state listViewItem.SubItems[1].Text = progress.ToString(); // update the progress listView.EndUpdate();
I’ve seen some solutions that involve overriding the component’s WndProc():
protected override void WndProc(ref Message m) { if (m.Msg == (int)WM.WM_ERASEBKGND) { m.Msg = (int)IntPtr.Zero; } base.WndProc(ref m); }
They say it solves the problem, but in my case It didn’t. I believe this is because I’m using icons on every item.
To end this question, here is a helper class that should be called when the form is loading for each ListView or any other ListView’s derived control in your form. Thanks to ‘Brian Gillespie’ for giving the solution.