System.Windows.Forms.DataGridViewRow Class

Represents a row in a System.Windows.Forms.DataGridView control.

See Also: DataGridViewRow Members


public class DataGridViewRow : DataGridViewBand


The System.Windows.Forms.DataGridViewRow class represents a row in a System.Windows.Forms.DataGridView control. You can retrieve rows through the DataGridView.Rows and DataGridView.SelectedRows collections of the control.

Unlike a System.Windows.Forms.DataGridViewColumn, a System.Windows.Forms.DataGridViewRow physically contains a collection of all of the cells in that row. You can access this collection through the DataGridViewRow.Cells property.

The System.Windows.Forms.DataGridViewRow class is used to access the individual cell elements, as well as to adjust the appearance and behavior of the row user interface (UI), such as height and cell style. Typically, you will want all rows or most rows in the control to share the same characteristics. To set cell styles for all rows in the control, set the properties of the object returned by the DataGridView.RowsDefaultCellStyle property. To set styles for alternating rows, use the DataGridView.AlternatingRowsDefaultCellStyle property. For more information about cell styles, see Cell Styles in the Windows Forms DataGridView Control. You can also use the DataGridView.RowTemplate property to define a row that will be used as a basis for all rows added to the control.

The System.Windows.Forms.DataGridView control will share System.Windows.Forms.DataGridViewRow objects across multiple data rows whenever possible to avoid performance penalties. Unless you are working with large amounts of data and experiencing performance issues, you can typically ignore row sharing. A shared row is indicated by an DataGridViewBand.Index property value of -1. Some members of the System.Windows.Forms.DataGridViewRow class cannot be used with shared rows, but you can unshare a row by accessing it through the DataGridViewRowCollection.Item(int) property. Rows can also become unshared in other ways. To access a row without unsharing it, use the DataGridViewRowCollection.SharedRow(int) method. When working with large amounts of data, you should be aware of how rows are shared and unshared to avoid performance penalties. For more information, see Best Practices for Scaling the Windows Forms DataGridView Control.


Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions:
Since: .NET 2.0