DataGridViewRow.Cells Property

Definition

Gets the collection of cells that populate the row.

C#
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewCellCollection Cells { get; }

Property Value

A DataGridViewCellCollection that contains all of the cells in the row.

Attributes

Examples

The following code example uses the Cells property to set the value of a cell in the row. This code example is part of a larger code example provided in How to: Manipulate Rows in the Windows Forms DataGridView Control.

C#
// Give cheescake excellent rating.
private void Button8_Click(object sender,
    System.EventArgs e)
{
    UpdateStars(dataGridView.Rows[4], "******************");
}

int ratingColumn = 3;

private void UpdateStars(DataGridViewRow row, string stars)
{

    row.Cells[ratingColumn].Value = stars;

    // Resize the column width to account for the new value.
    row.DataGridView.AutoResizeColumn(ratingColumn, 
        DataGridViewAutoSizeColumnMode.DisplayedCells);
}

Remarks

If the row does not contain any cells when this property is accessed, a new empty DataGridViewCellCollection will be created by a call to the CreateCellsInstance method.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

See also