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

설명

CellValueChanged 에 다른 값을 할당하면 컨트롤의 DataGridView 이벤트가 발생합니다.

속성은 Value 셀에 포함된 실제 데이터 개체인 반면 FormattedValue 속성은 데이터의 형식이 지정된 표현입니다. 합니다 ValueTypeFormattedValueType 속성 데이터 형식의 이러한 값은 각각에 해당 합니다.

속성을 설정 Value 하면 지정된 값이 서식이 지정된 표시 값에서 기본 셀 값으로 자동으로 변환되지 않습니다. 예를 들어 DataGridViewCellStyle 셀에 적용된 는 무시되므로 를 로 DataGridViewCellStyle.NullValue 설정 Value 해도 속성 값DataGridViewCellStyle.DataSourceNullValue이 발생하지 않습니다.

적용 대상

추가 정보