How to: Set Alternating Row Styles for the Windows Forms DataGridView Control Using the Designer

Tabular data is often presented in a ledger-like format where alternating rows have different background colors. This format makes it easier for users to tell which cells are in each row, especially with wide tables that have many columns.

With the DataGridView control, you can specify complete style information for alternating rows. You can use style characteristics like foreground color and font, in addition to background color, to differentiate alternating rows. For more information, see Cell Styles in the Windows Forms DataGridView Control.

The following procedure requires a Windows Application project with a form containing a DataGridView control. For information about setting up such a project, see How to: Create a Windows Forms application project and How to: Add Controls to Windows Forms.

Define styles for alternating rows

  1. Select the DataGridView control in the designer.

  2. In the Properties window, click the ellipsis button (The Ellipsis button (...) in the Properties window of Visual Studio.) next to the AlternatingRowsDefaultCellStyle property.

  3. In the CellStyle Builder dialog box, define the style by setting the properties, and use the Preview pane to confirm your choices. The styles you specify are used for every other row displayed in the control, starting with the second one.

  4. To define styles for the remaining rows, repeat steps 2 and 3 using the RowsDefaultCellStyle property.


    Cells are displayed using styles inherited from multiple properties. For more information about style inheritance, see Cell Styles in the Windows Forms DataGridView Control.

See also