DataGridViewDataErrorEventArgs Clase

Definición

Proporciona datos para el evento 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
Herencia

Ejemplos

En el ejemplo de código siguiente se muestra cómo responder a la información proporcionada por la DataGridViewDataErrorEventArgs clase . Este ejemplo forma parte de un ejemplo más grande disponible en el tema de información general de la DataGridViewComboBoxColumn clase.

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

Comentarios

Controlar el DataError evento le permite controlar las excepciones producidas por código fuera del control (por ejemplo, por un origen de datos externo). Utilice la Context propiedad para determinar el estado de DataGridView en el momento de la excepción. Utilice la Exception propiedad para recuperar los datos de excepción. Si desea controlar la excepción mediante controladores de eventos adicionales, establezca la ThrowException propiedad trueen .

Las ColumnIndex propiedades y RowIndex normalmente indican la celda en la que se produjo el error de datos. Sin embargo, cuando se produce el error en un origen de datos externo, es posible que el origen de datos no proporcione la columna en la que se produjo el error. En este caso, la ColumnIndex propiedad normalmente indica la columna de la celda actual en el momento del error.

Constructores

DataGridViewDataErrorEventArgs(Exception, Int32, Int32, DataGridViewDataErrorContexts)

Inicializa una nueva instancia de la clase DataGridViewDataErrorEventArgs.

Propiedades

Cancel

Obtiene o establece un valor que indica si se debe cancelar el evento.

(Heredado de CancelEventArgs)
ColumnIndex

Obtiene el índice de columna de la celda para la que se produce el evento.

(Heredado de DataGridViewCellCancelEventArgs)
Context

Obtiene los detalles sobre el estado del control DataGridView cuando se ha producido el error.

Exception

Obtiene la excepción que representa el error.

RowIndex

Obtiene el índice de fila de la celda para la que se produce el evento.

(Heredado de DataGridViewCellCancelEventArgs)
ThrowException

Obtiene o establece un valor que indica si se produce la excepción después de que el delegado DataGridViewDataErrorEventHandler haya acabado con él.

Métodos

Equals(Object)

Determina si el objeto especificado es igual que el objeto actual.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del Object actual.

(Heredado de Object)
ToString()

Devuelve una cadena que representa el objeto actual.

(Heredado de Object)

Se aplica a

Consulte también