DataGridViewRow.Cells Propriété

Définition

Obtient la collection de cellules qui remplissent la ligne.Gets the collection of cells that populate the row.

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

Valeur de propriété

DataGridViewCellCollection qui contient toutes les cellules de la ligne.A DataGridViewCellCollection that contains all of the cells in the row.

Attributs

Exemples

L’exemple de code suivant utilise la propriété Cells pour définir la valeur d’une cellule dans la ligne.The following code example uses the Cells property to set the value of a cell in the row. Cet exemple de code fait partie d’un exemple de code plus large fourni dans Comment : Manipuler des lignes dans le Windows Formsde contrôle DataGridView.This code example is part of a larger code example provided in How to: Manipulate Rows in the Windows Forms DataGridView Control.

// 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

Remarques

Si la ligne ne contient pas de cellules lors de l’accès à cette propriété, un nouvel DataGridViewCellCollection vide est créé par un appel à la méthode CreateCellsInstance.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.

S’applique à

Voir aussi