Share via


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

Tabular data is often presented to users 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. This enables you use style characteristics like foreground color and font, in addition to background color, to differentiate alternating rows.

There is support for this task in Visual Studio. How to: Set Alternating Row Styles for the Windows Forms DataGridView Control Using the Designer
How to: Set Alternating Row Styles for the Windows Forms DataGridView Control Using the Designer
How to: Set Alternating Row Styles for the Windows Forms DataGridView Control Using the Designer
How to: Set Alternating Row Styles for the Windows Forms DataGridView Control Using the Designer

To set alternating row styles programmatically

Compiling the Code

This example requires:

Robust Programming

For maximum scalability, you should share DataGridViewCellStyle objects across multiple rows, columns, or cells that use the same styles, rather than setting the style properties for each element separately. For more information, see Best Practices for Scaling the Windows Forms DataGridView Control.

See Also

Tasks

How to: Set Font and Color Styles in the Windows Forms DataGridView Control

Concepts

Cell Styles in the Windows Forms DataGridView Control

Best Practices for Scaling the Windows Forms DataGridView Control

Reference

DataGridView.AlternatingRowsDefaultCellStyle

DataGridView.RowsDefaultCellStyle

DataGridView

DataGridViewCellStyle

Other Resources

Basic Formatting and Styling in the Windows Forms DataGridView Control