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 type exposes the following members.

Public methodDataGridViewRowInitializes a new instance of the DataGridViewRow class without using a template.

Public propertyAccessibilityObjectGets the DataGridViewRow.DataGridViewRowAccessibleObject assigned to the DataGridViewRow.
Public propertyCellsGets the collection of cells that populate the row.
Public propertyContextMenuStripGets or sets the shortcut menu for the row. (Overrides DataGridViewBand.ContextMenuStrip.)
Public propertyDataBoundItemGets the data-bound object that populated the row.
Public propertyDataGridViewGets the DataGridView control associated with this element. (Inherited from DataGridViewElement.)
Public propertyDefaultCellStyleGets or sets the default styles for the row, which are used to render cells in the row unless the styles are overridden. (Overrides DataGridViewBand.DefaultCellStyle.)
Public propertyDefaultHeaderCellTypeGets or sets the run-time type of the default header cell. (Inherited from DataGridViewBand.)
Public propertyDisplayedGets a value indicating whether this row is displayed on the screen. (Overrides DataGridViewBand.Displayed.)
Public propertyDividerHeightGets or sets the height, in pixels, of the row divider.
Public propertyErrorTextGets or sets the error message text for row-level errors.
Public propertyFrozenGets or sets a value indicating whether the row is frozen. (Overrides DataGridViewBand.Frozen.)
Public propertyHasDefaultCellStyleGets a value indicating whether the DefaultCellStyle property has been set. (Inherited from DataGridViewBand.)
Public propertyHeaderCellGets or sets the row's header cell.
Protected propertyHeaderCellCoreGets or sets the header cell of the DataGridViewBand. (Inherited from DataGridViewBand.)
Public propertyHeightGets or sets the current height of the row.
Public propertyIndexGets the relative position of the band within the DataGridView control. (Inherited from DataGridViewBand.)
Public propertyInheritedStyleGets the cell style in effect for the row. (Overrides DataGridViewBand.InheritedStyle.)
Public propertyIsNewRowGets a value indicating whether the row is the row for new records.
Protected propertyIsRowGets a value indicating whether the band represents a row. (Inherited from DataGridViewBand.)
Public propertyMinimumHeightGets or sets the minimum height of the row.
Public propertyReadOnlyGets or sets a value indicating whether the row is read-only. (Overrides DataGridViewBand.ReadOnly.)
Public propertyResizableGets or sets a value indicating whether users can resize the row or indicating that the behavior is inherited from the DataGridView.AllowUserToResizeRows property. (Overrides DataGridViewBand.Resizable.)
Public propertySelectedGets or sets a value indicating whether the row is selected. (Overrides DataGridViewBand.Selected.)
Public propertyStateGets the current state of the row. (Overrides DataGridViewElement.State.)
Public propertyTagGets or sets the object that contains data to associate with the band. (Inherited from DataGridViewBand.)
Public propertyVisibleGets or sets a value indicating whether the row is visible. (Overrides DataGridViewBand.Visible.)

Public methodAdjustRowHeaderBorderStyleModifies an input row header border style according to the specified criteria.
Public methodCloneCreates an exact copy of this row. (Overrides DataGridViewBand.Clone().)
Protected methodCreateAccessibilityInstanceCreates a new accessible object for the DataGridViewRow.
Public methodCreateCells(DataGridView)Clears the existing cells and sets their template according to the supplied DataGridView template.
Public methodCreateCells(DataGridView, Object[])Clears the existing cells and sets their template and values.
Protected methodCreateCellsInstanceConstructs a new collection of cells based on this row.
Public methodDispose()Releases all resources used by the DataGridViewBand. (Inherited from DataGridViewBand.)
Protected methodDispose(Boolean)Releases the unmanaged resources used by the DataGridViewBand and optionally releases the managed resources. (Inherited from DataGridViewBand.)
Protected methodDrawFocusDraws a focus rectangle around the specified bounds.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeReleases the resources associated with the band. (Inherited from DataGridViewBand.)
Public methodGetContextMenuStripGets the shortcut menu for the row.
Public methodGetErrorTextGets the error text for the row at the specified index.
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetPreferredHeightCalculates the ideal height of the specified row based on the specified criteria.
Public methodGetStateReturns a value indicating the current state of the row.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected methodOnDataGridViewChangedCalled when the band is associated with a different DataGridView. (Inherited from DataGridViewBand.)
Protected methodPaintPaints the current row.
Protected methodPaintCellsPaints the cells in the current row.
Protected methodPaintHeaderPaints the header cell of the current row.
Protected methodRaiseCellClickRaises the DataGridView.CellClick event. (Inherited from DataGridViewElement.)
Protected methodRaiseCellContentClickRaises the DataGridView.CellContentClick event. (Inherited from DataGridViewElement.)
Protected methodRaiseCellContentDoubleClickRaises the DataGridView.CellContentDoubleClick event. (Inherited from DataGridViewElement.)
Protected methodRaiseCellValueChangedRaises the DataGridView.CellValueChanged event. (Inherited from DataGridViewElement.)
Protected methodRaiseDataErrorRaises the DataGridView.DataError event. (Inherited from DataGridViewElement.)
Protected methodRaiseMouseWheelRaises the Control.MouseWheel event. (Inherited from DataGridViewElement.)
Public methodSetValuesSets the values of the row's cells.
Public methodToStringGets a human-readable string that describes the row. (Overrides DataGridViewBand.ToString().)

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;

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

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

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