views:

168

answers:

2

Using C# Winforms (3.5).

Is it possible to set the row colors to automatically alternate in a listview?

Or do I need to manually set the row color each time a new row is added to the listview?

Based on a MSDN article the manual method would look like this:

//alternate row color
if (i % 2 == 0)
{
    lvi.BackColor = Color.LightBlue;
}
else
{
    lvi.BackColor = Color.Beige;
}
+2  A: 

I'm afraid that is the only way in Winforms. XAML allows this through use of styles though.

Andre
Thanks for the feedback @Andre.
John M
A: 

As far as I know WPF allows to set style on any control using <Styles/> But in winforms I'm afraid may be that's the only way.

Johnny