DataGridViewCellValidatingEventArgs 클래스

정의

CellValidating 컨트롤의 DataGridView 이벤트에 대한 데이터를 제공합니다.

public ref class DataGridViewCellValidatingEventArgs : System::ComponentModel::CancelEventArgs
public class DataGridViewCellValidatingEventArgs : System.ComponentModel.CancelEventArgs
type DataGridViewCellValidatingEventArgs = class
    inherit CancelEventArgs
Public Class DataGridViewCellValidatingEventArgs
Inherits CancelEventArgs
상속
DataGridViewCellValidatingEventArgs

예제

다음 코드 예제에서는 처리 된 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

설명

DataGridView.CellValidating 이벤트를 사용 하면 새 값을 유효 하지 않을 때 현재 셀의 변경 내용을 취소 합니다. 사용 된 FormattedValue 현재 값을 확인 하는 속성입니다. 현재 셀의 상태를 확인 하려면 사용 합니다 RowIndexColumnIndex 속성을 통해 셀에 액세스를 DataGridView.Rows 컬렉션입니다. 변경 내용을 취소를 설정 합니다 Cancel 속성을 true합니다.

이 이벤트는 데이터 바인딩 모드에서 취소 된 경우 새 값이 기본 데이터 원본에 푸시되 지 않습니다. 이 이벤트는 가상 모드에 취소 될 때를 DataGridView.CellValuePushed 이벤트 발생 하지 것입니다.

속성

Cancel

이벤트를 취소해야 할지 여부를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 CancelEventArgs)
ColumnIndex

유효성을 검사해야 하는 셀의 열 인덱스를 가져옵니다.

FormattedValue

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

RowIndex

유효성을 검사해야 하는 셀의 행 인덱스를 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보