DataGridViewDataErrorEventArgs Klasa

Definicja

Udostępnia dane dla zdarzenia DataError.

public ref class DataGridViewDataErrorEventArgs : System::Windows::Forms::DataGridViewCellCancelEventArgs
public class DataGridViewDataErrorEventArgs : System.Windows.Forms.DataGridViewCellCancelEventArgs
type DataGridViewDataErrorEventArgs = class
    inherit DataGridViewCellCancelEventArgs
Public Class DataGridViewDataErrorEventArgs
Inherits DataGridViewCellCancelEventArgs
Dziedziczenie

Przykłady

W poniższym przykładzie kodu pokazano, jak reagować na informacje dostarczone przez klasę DataGridViewDataErrorEventArgs . Ten przykład jest częścią większego przykładu dostępnego w temacie DataGridViewComboBoxColumn przeglądu klasy.

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

Uwagi

Obsługa zdarzenia DataError umożliwia obsługę wyjątków zgłaszanych przez kod poza kontrolą (na przykład przez zewnętrzne źródło danych). Context Użyj właściwości , aby określić stan DataGridView w momencie wystąpienia wyjątku. Exception Użyj właściwości , aby pobrać dane wyjątku. Jeśli chcesz obsłużyć wyjątek przez dodatkowe procedury obsługi zdarzeń, ustaw ThrowException właściwość na true.

Właściwości ColumnIndex i RowIndex zwykle wskazują komórkę, w której wystąpił błąd danych. Jeśli jednak błąd występuje w zewnętrznym źródle danych, źródło danych może nie podać kolumny, w której wystąpił błąd. W takim przypadku ColumnIndex właściwość zazwyczaj wskazuje kolumnę bieżącej komórki w momencie wystąpienia błędu.

Konstruktory

DataGridViewDataErrorEventArgs(Exception, Int32, Int32, DataGridViewDataErrorContexts)

Inicjuje nowe wystąpienie klasy DataGridViewDataErrorEventArgs.

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, dla którego występuje zdarzenie.

(Odziedziczone po DataGridViewCellCancelEventArgs)
Context

Pobiera szczegółowe informacje o stanie DataGridView wystąpienia błędu.

Exception

Pobiera wyjątek reprezentujący błąd.

RowIndex

Pobiera indeks wiersza komórki, dla którego występuje zdarzenie.

(Odziedziczone po DataGridViewCellCancelEventArgs)
ThrowException

Pobiera lub ustawia wartość wskazującą, czy zgłosić wyjątek po zakończeniu delegowania DataGridViewDataErrorEventHandler .

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 wartość bieżącego wystąpienia.

(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ż