Winforms - How to alternate the color of rows in a ListView control?

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.


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