How to: Use the Row Template to Customize Rows in the Windows Forms DataGridView Control

The DataGridView control uses the row template as a basis for all rows that it adds to the control either through data binding or when you call the System.Windows.Forms.DataGridViewRowCollection.Add method without specifying an existing row to use.

The row template gives you greater control over the appearance and behavior of rows than the RowsDefaultCellStyle property provides. With the row template, you can set any DataGridViewRow properties, including DefaultCellStyle.

There are some situations where you must use the row template to achieve a particular effect. For example, row height information cannot be stored in a DataGridViewCellStyle, so you must use a row template to change the default height used by all rows. The row template is also useful when you create your own classes derived from DataGridViewRow and you want your custom type used when new rows are added to the control.


The row template is used only when rows are added. You cannot change existing rows by changing the row template.

To use the row template

Compiling the Code

This example requires:

See Also