DataGridViewRow.Cells Propiedad

Definición

Obtiene la colección de celdas que rellenan la fila.

public:
 property System::Windows::Forms::DataGridViewCellCollection ^ Cells { System::Windows::Forms::DataGridViewCellCollection ^ get(); };
[System.ComponentModel.Browsable(false)]
public System.Windows.Forms.DataGridViewCellCollection Cells { get; }
[<System.ComponentModel.Browsable(false)>]
member this.Cells : System.Windows.Forms.DataGridViewCellCollection
Public ReadOnly Property Cells As DataGridViewCellCollection

Valor de propiedad

DataGridViewCellCollection

DataGridViewCellCollection que contiene todas las celdas de la fila.

Atributos

Ejemplos

En el ejemplo de código siguiente se usa la Cells propiedad para establecer el valor de una celda de la fila. Este ejemplo de código forma parte de un ejemplo de código más grande que se proporciona en Cómo: Manipular filas en el control DataGridView de Windows Forms.

// Give cheescake excellent rating.
void Button8_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   UpdateStars( dataGridView->Rows[ 4 ], L"******************" );
}

int ratingColumn;
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 );
}
// 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);
}
' Give cheescake excellent rating.
Private Sub Button8_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button8.Click

    UpdateStars(dataGridView.Rows(4), "******************")
End Sub

Private ratingColumn As Integer = 3

Private Sub UpdateStars(ByVal row As DataGridViewRow, _
    ByVal stars As String)

    row.Cells(ratingColumn).Value = stars

    ' Resize the column width to account for the new value.
    row.DataGridView.AutoResizeColumn(ratingColumn, _
        DataGridViewAutoSizeColumnMode.DisplayedCells)

End Sub

Comentarios

Si la fila no contiene ninguna celda cuando se accede a esta propiedad, se creará un nuevo vacío DataGridViewCellCollection mediante una llamada al CreateCellsInstance método .

Se aplica a

Consulte también