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
Set the ListView OwnerDraw property to true and then implement the DrawItem handler :
private void listView_DrawItem(object sender, DrawListViewItemEventArgs e)
{
e.DrawDefault = true;
if ((e.ItemIndex%2) == 1)
{
e.Item.BackColor = Color.FromArgb(230, 230, 255);
e.Item.UseItemStyleForSubItems = true;
}
}
private void listView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
e.DrawDefault = true;
}
This example is a simple one, you can improve it.