DataGridViewDataErrorEventArgs.Context 속성

정의

오류가 발생했을 때의 DataGridView 상태에 대한 세부 내용을 가져옵니다.

public:
 property System::Windows::Forms::DataGridViewDataErrorContexts Context { System::Windows::Forms::DataGridViewDataErrorContexts get(); };
public System.Windows.Forms.DataGridViewDataErrorContexts Context { get; }
member this.Context : System.Windows.Forms.DataGridViewDataErrorContexts
Public ReadOnly Property Context As DataGridViewDataErrorContexts

속성 값

오류가 발생한 컨텍스트를 지정하는 DataGridViewDataErrorContexts 값의 비트 조합입니다.

예제

다음 코드 예제에서는 오류 컨텍스트를 조사 하는 방법에 설명 합니다. 이 예제는에서 사용할 수 있는 보다 큰 예제의 일부는 DataGridViewComboBoxColumn 클래스 개요 항목입니다.

private:
    void DataGridView1_DataError(Object^ sender, DataGridViewDataErrorEventArgs^ anError)
    {

        MessageBox::Show("Error happened " + anError->Context.ToString());

        if (anError->Context == DataGridViewDataErrorContexts::Commit)
        {
            MessageBox::Show("Commit error");
        }
        if (anError->Context == DataGridViewDataErrorContexts::CurrentCellChange)
        {
            MessageBox::Show("Cell change");
        }
        if (anError->Context == DataGridViewDataErrorContexts::Parsing)
        {
            MessageBox::Show("parsing error");
        }
        if (anError->Context == DataGridViewDataErrorContexts::LeaveControl)
        {
            MessageBox::Show("leave control error");
        }

        if (dynamic_cast<ConstraintException^>(anError->Exception) != nullptr)
        {
            DataGridView^ view = (DataGridView^)sender;
            view->Rows[anError->RowIndex]->ErrorText = "an error";
            view->Rows[anError->RowIndex]->Cells[anError->ColumnIndex]->ErrorText = "an error";

            anError->ThrowException = false;
        }
    }
private void DataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs anError)
{

    MessageBox.Show("Error happened " + anError.Context.ToString());

    if (anError.Context == DataGridViewDataErrorContexts.Commit)
    {
        MessageBox.Show("Commit error");
    }
    if (anError.Context == DataGridViewDataErrorContexts.CurrentCellChange)
    {
        MessageBox.Show("Cell change");
    }
    if (anError.Context == DataGridViewDataErrorContexts.Parsing)
    {
        MessageBox.Show("parsing error");
    }
    if (anError.Context == DataGridViewDataErrorContexts.LeaveControl)
    {
        MessageBox.Show("leave control error");
    }

    if ((anError.Exception) is ConstraintException)
    {
        DataGridView view = (DataGridView)sender;
        view.Rows[anError.RowIndex].ErrorText = "an error";
        view.Rows[anError.RowIndex].Cells[anError.ColumnIndex].ErrorText = "an error";

        anError.ThrowException = false;
    }
}
Private Sub DataGridView1_DataError(ByVal sender As Object, _
ByVal e As DataGridViewDataErrorEventArgs) _
Handles DataGridView1.DataError

    MessageBox.Show("Error happened " _
        & e.Context.ToString())

    If (e.Context = DataGridViewDataErrorContexts.Commit) _
        Then
        MessageBox.Show("Commit error")
    End If
    If (e.Context = DataGridViewDataErrorContexts _
        .CurrentCellChange) Then
        MessageBox.Show("Cell change")
    End If
    If (e.Context = DataGridViewDataErrorContexts.Parsing) _
        Then
        MessageBox.Show("parsing error")
    End If
    If (e.Context = _
        DataGridViewDataErrorContexts.LeaveControl) Then
        MessageBox.Show("leave control error")
    End If

    If (TypeOf (e.Exception) Is ConstraintException) Then
        Dim view As DataGridView = CType(sender, DataGridView)
        view.Rows(e.RowIndex).ErrorText = "an error"
        view.Rows(e.RowIndex).Cells(e.ColumnIndex) _
            .ErrorText = "an error"

        e.ThrowException = False
    End If
End Sub

설명

멤버는 DataGridViewDataErrorContexts 비트를 사용 하 여 열거형을 결합할 수 있습니다 OR 연산자는 데이터 바인딩된의 상태를 나타내는 DataGridView 데이터 오류가 발생 합니다. 예를 들어, 사용자가 잘못 된 셀 값 (예: 날짜를 해야 하는 셀의 이름 입력)를 입력 하는 경우 다음 다른 셀을 선택 하 고는 DataGridView 잘못 된 셀 값을 커밋하려고 시도 합니다. 커밋에 실패 하면 합니다 DataGridView 시킵니다를 DataError 이벤트입니다 Context 속성의 값이 포함 됩니다 CommitCurrentCellChange합니다.

적용 대상

추가 정보