DataGridViewRow.Cells 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得填入資料列的儲存格集合。
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
屬性值
DataGridViewCellCollection,包含資料列中的所有儲存格。
- 屬性
範例
下列程式碼範例會 Cells 使用 屬性來設定資料列中儲存格的值。 此程式碼範例是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
備註
如果存取這個屬性時,資料列不包含任何儲存格,方法的呼叫 CreateCellsInstance 將會建立新的空白 DataGridViewCellCollection 。