DataGridView.DataError Event
.NET Framework 2.0
Note: This event is new in the .NET Framework version 2.0.
Occurs when an external data-parsing or validation operation throws an exception, or when an attempt to commit data to a data source fails.
Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)
Assembly: System.Windows.Forms (in system.windows.forms.dll)
'Declaration Public Event DataError As DataGridViewDataErrorEventHandler 'Usage Dim instance As DataGridView Dim handler As DataGridViewDataErrorEventHandler AddHandler instance.DataError, handler
/** @event */ public void add_DataError (DataGridViewDataErrorEventHandler value) /** @event */ public void remove_DataError (DataGridViewDataErrorEventHandler value)
JScript supports the use of events, but not the declaration of new ones.
The DataError event enables you to handle exceptions thrown in code that is called by the control during data processing operations.
For more information about handling events, see Consuming Events.
The following code example demonstrates a DataError event handler.
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
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.
Community Additions
ADD
Show: