DataGridViewCell.Value プロパティ

定義

このセルに関連付けられている値を取得または設定します。

public:
 property System::Object ^ Value { System::Object ^ get(); void set(System::Object ^ value); };
[System.ComponentModel.Browsable(false)]
public object Value { get; set; }
[System.ComponentModel.Browsable(false)]
public object? Value { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.Value : obj with get, set
Public Property Value As Object

プロパティ値

セルに表示されるデータを取得または設定します。 既定値は、null です。

属性

例外

RowIndex が有効な範囲 (0 ~コントロールの行数 - 1) 内にありません。

ColumnIndex が 0 未満です。これは、セルが行ヘッダーのセルであることを示します。

次のコード例は、 プロパティを使用してセルの内容を更新する方法を Value 示しています。 この例は、「方法: Windows フォーム DataGridView コントロールの行を操作する」で提供されるより大きなコード例の一部です。

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

注釈

セルに別の値を割り当てると、コントロールのCellValueChangedDataGridViewイベントが発生します。

プロパティは Value セルに含まれる実際のデータ オブジェクトですが FormattedValue 、 プロパティはデータの書式設定された表現です。 プロパティと FormattedValueType プロパティはValueType、それぞれこれらの値のデータ型に対応します。

プロパティを Value 設定しても、指定した値は書式設定された表示値から基になるセル値に自動的に変換されません。 たとえば、DataGridViewCellStyleセルに対して有効な は無視されるため、 を にDataGridViewCellStyle.NullValue設定Valueしても、 プロパティ値DataGridViewCellStyle.DataSourceNullValueは 発生しません。

適用対象

こちらもご覧ください