DataGridViewCellValidatingEventHandler 대리자

정의

CellValidatingDataGridView 이벤트를 처리할 메서드를 나타냅니다.

public delegate void DataGridViewCellValidatingEventHandler(System::Object ^ sender, DataGridViewCellValidatingEventArgs ^ e);
public delegate void DataGridViewCellValidatingEventHandler(object sender, DataGridViewCellValidatingEventArgs e);
public delegate void DataGridViewCellValidatingEventHandler(object? sender, DataGridViewCellValidatingEventArgs e);
type DataGridViewCellValidatingEventHandler = delegate of obj * DataGridViewCellValidatingEventArgs -> unit
Public Delegate Sub DataGridViewCellValidatingEventHandler(sender As Object, e As DataGridViewCellValidatingEventArgs)

매개 변수

sender
Object

이벤트 전송자에 대한 참조입니다.

e
DataGridViewCellValidatingEventArgs

이벤트 데이터를 포함하는 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

설명

CellValidating 이벤트 셀 콘텐츠 유효성 검사를 사용 하도록 설정 하는 입력된 포커스를 잃을 때 발생 합니다. 이 이벤트를 취소 하면 현재 셀에 변경 내용을 취소 합니다. 이 이벤트는 데이터 바인딩 모드에서 취소 된 경우 새 값이 기본 데이터 원본에 푸시되 지 않습니다. 이 이벤트는 가상 모드에 취소 될 때를 CellValuePushed 이벤트 발생 하지 것입니다.

DataGridViewCellValidatingEventHandler 대리자를 만들 때, 이벤트를 처리할 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다. 이벤트 처리기 대리자에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

확장 메서드

GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상

추가 정보