DataGridViewCellValidatingEventArgs Klasa

Definicja

Udostępnia dane dotyczące CellValidating zdarzenia kontrolki DataGridView .

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

Przykłady

Poniższy przykład kodu obsługuje zdarzenie, CellValidating aby upewnić się, że tylko dodatnie liczby całkowite są wprowadzane przez użytkownika. Ten przykład jest częścią większego przykładu dostępnego w temacie referencyjnym 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

Uwagi

Zdarzenie DataGridView.CellValidating umożliwia anulowanie zmian w bieżącej komórce, gdy nowa wartość jest nieprawidłowa. Użyj właściwości , FormattedValue aby określić bieżącą wartość. Aby określić stan bieżącej komórki, użyj RowIndex właściwości i ColumnIndex , aby uzyskać dostęp do komórki za pośrednictwem DataGridView.Rows kolekcji. Aby anulować zmianę, ustaw Cancel właściwość na true.

Po anulowaniu tego zdarzenia w trybie powiązanym z danymi nowa wartość nie jest wypychana do bazowego źródła danych. Po anulowaniu tego zdarzenia w trybie DataGridView.CellValuePushed wirtualnym zdarzenie nie zostanie zgłoszone.

Właściwości

Cancel

Pobiera lub ustawia wartość wskazującą, czy zdarzenie powinno zostać anulowane.

(Odziedziczone po CancelEventArgs)
ColumnIndex

Pobiera indeks kolumn komórki, która musi zostać zweryfikowana.

FormattedValue

Pobiera sformatowaną zawartość komórki, która musi zostać zweryfikowana.

RowIndex

Pobiera indeks wierszy komórki, która musi zostać zweryfikowana.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Zobacz też