DataGridViewDataErrorEventArgs Třída

Definice

Poskytuje data pro událost 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
Dědičnost

Příklady

Následující příklad kódu ukazuje, jak reagovat na informace poskytnuté DataGridViewDataErrorEventArgs třídou . Tento příklad je součástí většího příkladu, který je k dispozici v tématu přehledu DataGridViewComboBoxColumn třídy.

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

Poznámky

DataError Zpracování události umožňuje zpracovat výjimky vyvolané kódem mimo vaši kontrolu (například externím zdrojem dat). Context Pomocí vlastnosti určete stav objektu DataGridView v době výjimky. Exception Pomocí vlastnosti načtěte data výjimky. Pokud chcete výjimku zpracovat dalšími obslužnými rutiny událostí, nastavte ThrowException vlastnost na true.

Vlastnosti ColumnIndex a RowIndex obvykle označují buňku, ve které došlo k chybě dat. Pokud k chybě dojde v externím zdroji dat, zdroj dat nemusí poskytnout sloupec, ve kterém k chybě došlo. V tomto případě ColumnIndex vlastnost obvykle označuje sloupec aktuální buňky v době chyby.

Konstruktory

DataGridViewDataErrorEventArgs(Exception, Int32, Int32, DataGridViewDataErrorContexts)

Inicializuje novou instanci DataGridViewDataErrorEventArgs třídy .

Vlastnosti

Cancel

Získá nebo nastaví hodnotu označující, zda má být událost zrušena.

(Zděděno od CancelEventArgs)
ColumnIndex

Získá index sloupce buňky, pro kterou dochází k události.

(Zděděno od DataGridViewCellCancelEventArgs)
Context

Získá podrobnosti o stavu DataGridView , kdy došlo k chybě.

Exception

Získá výjimku, která představuje chybu.

RowIndex

Získá index řádku buňky, pro kterou dochází k události.

(Zděděno od DataGridViewCellCancelEventArgs)
ThrowException

Získá nebo nastaví hodnotu označující, zda má být vyvolání výjimky po DataGridViewDataErrorEventHandler dokončení delegáta s ním.

Metody

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí hashovací funkce.

(Zděděno od Object)
GetType()

Type Získá z aktuální instance.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Platí pro

Viz také