영어로 읽기

다음을 통해 공유


DataGridViewRow.ErrorText 속성

정의

행 수준 오류에 대한 오류 메시지 텍스트를 가져오거나 설정합니다.

public string ErrorText { get; set; }

속성 값

오류 메시지를 포함하는 String입니다.

예외

이 속성의 값을 가져올 때 행이 DataGridView 컨트롤의 공유 행인 경우

예제

다음 코드 예제를 사용 ErrorText 하는 방법에 설명 합니다 이벤트 처리기에서 속성입니다 DataError . 이 예제는에서 사용할 수 있는 보다 큰 예제의 일부는 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 ((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;
    }
}

설명

행 수준 오류에 대한 오류 메시지를 제공하려면 이 속성을 사용합니다. 사용자가 행 머리글에 표시된 오류 아이콘 위로 마우스 포인터를 이동하면 지정된 메시지가 도구 설명에 표시됩니다.

.NET Framework 4.5.2부터 app.config 파일에 다음 항목이 포함된 경우 시스템 DPI 설정에 따라 오류 아이콘의 크기가 조정됩니다.

<appSettings>
  <add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
</appSettings>

이 행이 컨트롤과 DataGridView 연결된 경우 이 속성을 설정하면 이벤트가 발생합니다 RowErrorTextChanged .

적용 대상

제품 버전
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

추가 정보