DataGridViewCellValidatingEventArgs.FormattedValue 속성

정의

유효성을 검사해야 하는 셀의 서식이 지정된 내용을 가져옵니다.

public:
 property System::Object ^ FormattedValue { System::Object ^ get(); };
public object FormattedValue { get; }
public object? FormattedValue { get; }
member this.FormattedValue : obj
Public ReadOnly Property FormattedValue As Object

속성 값

서식이 지정된 값에 대한 참조입니다.

예제

다음 코드 예제에서는 처리 된 CellValidating 이벤트를 사용자가 양의 정수만 입력 되어 있는지 확인 합니다. 이 예제는에서 사용할 수 있는 보다 큰 예제의 일부는 VirtualMode 참조 항목입니다.

void VirtualConnector::dataGridView1_CellValidating
    (Object^ sender, DataGridViewCellValidatingEventArgs^ e)
{
    int newInteger;

    // Don't try to validate the 'new row' until finished 
    // editing since there
    // is not any point in validating its initial value.
    if (dataGridView1->Rows[e->RowIndex]->IsNewRow) 
    {
        return; 
    }
    if (!Int32::TryParse(e->FormattedValue->ToString(), 
        newInteger) || (newInteger < 0))
    {
        e->Cancel = true;
    }
}
private void dataGridView1_CellValidating(object sender,
    DataGridViewCellValidatingEventArgs e)
{
    dataGridView1.Rows[e.RowIndex].ErrorText = "";
    int newInteger;

    // Don't try to validate the 'new row' until finished 
    // editing since there
    // is not any point in validating its initial value.
    if (dataGridView1.Rows[e.RowIndex].IsNewRow) { return; }
    if (!int.TryParse(e.FormattedValue.ToString(),
        out newInteger) || newInteger < 0)
    {
        e.Cancel = true;
        dataGridView1.Rows[e.RowIndex].ErrorText = "the value must be a non-negative integer";
    }
}
Private Sub dataGridView1_CellValidating(ByVal sender As Object, _
    ByVal e _
    As DataGridViewCellValidatingEventArgs) _
    Handles dataGridView1.CellValidating

    Me.dataGridView1.Rows(e.RowIndex).ErrorText = ""
    Dim newInteger As Integer

    ' Don't try to validate the 'new row' until finished 
    ' editing since there
    ' is not any point in validating its initial value.
    If dataGridView1.Rows(e.RowIndex).IsNewRow Then Return
    If Not Integer.TryParse(e.FormattedValue.ToString(), newInteger) _
        OrElse newInteger < 0 Then

        e.Cancel = True
        Me.dataGridView1.Rows(e.RowIndex).ErrorText = "the value must be a non-negative integer"

    End If
End Sub

설명

사용자 인터페이스 (UI)를 통해 사용자가 입력 한 텍스트가 FormattedValue 속성 값입니다. 이 유효성을 검사할 수 있는 값은 셀으로 구문 분석 전에 Value 속성 값입니다.

적용 대상

추가 정보