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
You can also take advantage of owner drawing, rather than setting properties explicitly. Owner drawing is less vulnerable to item reordering.
Here is how to do this in Better ListView (a 3rd party component offering both free and extended versions) - its a matter of simply handling a DrawItemBackground
event:
private void ListViewOnDrawItemBackground(object sender, BetterListViewDrawItemBackgroundEventArgs eventArgs)
{
if ((eventArgs.Item.Index & 1) == 1)
{
eventArgs.Graphics.FillRectangle(Brushes.AliceBlue, eventArgs.ItemBounds.BoundsOuter);
}
}
result: