Expand Minimize
0 out of 1 rated this helpful - Rate this topic

DataGridView.RowTemplate Property

Gets or sets the row that represents the template for all the rows in the control.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
'Declaration
<BrowsableAttribute(True)> _
Public Property RowTemplate As DataGridViewRow

Property Value

Type: System.Windows.Forms.DataGridViewRow
A DataGridViewRow representing the row template.
ExceptionCondition
InvalidOperationException

The specified row when setting this property has its DataGridView property set.

Sometimes you want greater control over the appearance of DataGridView rows than what is provided by the various DataGridView cell style properties. The RowTemplate property lets you create and initialize a DataGridViewRow for use as a template by all rows, including the row for new records if AllowUserToAddRows is true.

This is useful when you are setting default values for properties such as row height. For example, you may want to increase the default row height in order to provide extra room beneath ordinary cell content for displaying content that spans multiple columns.

Setting the row template is necessary when external data is displayed using custom types derived from the DataGridViewRow class. With unbound DataGridView controls, you can programmatically populate the Rows collection with instances of your custom row type. When displaying external data, however, the rows are generated automatically, but they are based on the row template, which you can set to an instance of your custom row type.

If this property has not been set the first time you retrieve its value, a new DataGridViewRow is created and returned.

The following code example illustrates how to use the row template to specify an initial row height and a minimum row height.

With Me.dataGridView1.RowTemplate
    .DefaultCellStyle.BackColor = Color.Bisque
    .Height = 35
    .MinimumHeight = 20
End With

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.