This documentation is archived and is not being maintained.

DataGridViewRow Class

Represents a row in a DataGridView control.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public class DataGridViewRow : DataGridViewBand

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

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

The 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 DataGridView control will share 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 Index property value of -1. Some members of the DataGridViewRow class cannot be used with shared rows, but you can unshare a row by accessing it through the DataGridViewRowCollection.Item property. Rows can also become unshared in other ways. To access a row without unsharing it, use the DataGridViewRowCollection.SharedRow 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.

Notes to Inheritors:

When you derive from DataGridViewRow and add new properties to the derived class, be sure to override the Clone method to copy the new properties during cloning operations. You should also call the base class's Clone method so that the properties of the base class are copied to the new cell.

The following code example illustrates the use of this type. This example is part of a larger example available in How to: Manipulate Rows in the Windows Forms DataGridView Control.

// Set row labels. 
private void Button6_Click(object sender, System.EventArgs e)

    int rowNumber = 1;
    foreach (DataGridViewRow row in dataGridView.Rows)
        if (row.IsNewRow) continue;
        row.HeaderCell.Value = "Row " + rowNumber;
        rowNumber = rowNumber + 1;

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

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

.NET Framework

Supported in: 3.5, 3.0, 2.0