changing BackColor in ListView causing screen flickering

changing BackColor in ListView causing screen flickering

Post by Sazonov Dm » Sat, 09 Apr 2005 05:12:04


I have listView with 200 items, details view, 5 columns.
Once a second, I'm changing BackColor property for some
of ListViewItem.
Whole screen terribly flickering.
I inherited from List View and tried
SetStyle(ControlStyles.DoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint,true);
UpdateStyles();
in constructor. Also, I tried same thing in MainForm.

Nothing help!

You may see this yourself: creat new winForms
application, add ListView, set docking:Fill,
style:Report, add 5-10 columns and timer (enabled, 1000
ms)
then add code

Random r = new Random();
private void Form1_Load(object sender, System.EventArgs e)
{
for(int i = 0; i<200; i++ )
listView1.Items.Add( new ListViewItem( new string[]{
i.ToString(), (i*2).ToString(), "", "", ""} ));
}

private void timer1_Tick(object sender, System.EventArgs
e)
{
for(int i = 0; i<30; i++ )
{
switch(r.Next(4))
{
case 0: c = Color.White;
break;
case 1: c = Color.Red;
break;
case 2: c = Color.Green;
break;
case 3: c = Color.Yellow;
break;
}
listView1.Items[r.Next(199)].BackColor = c;
}
}

when scroll to the end of list. It looks normal in the
beginign, but after while it became blink as hell. It
looks like ListView redraw all items with white back
color first, and then redraw it second time with item
color.

What should I do? Please help, gurus :-)