DataGridViewDataErrorEventArgs Class
Provides data for the DataError event.
System::EventArgs
System.ComponentModel::CancelEventArgs
System.Windows.Forms::DataGridViewCellCancelEventArgs
System.Windows.Forms::DataGridViewDataErrorEventArgs
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The DataGridViewDataErrorEventArgs type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | DataGridViewDataErrorEventArgs | Initializes a new instance of the DataGridViewDataErrorEventArgs class. |
| Name | Description | |
|---|---|---|
![]() | Cancel | Gets or sets a value indicating whether the event should be canceled. (Inherited from CancelEventArgs.) |
![]() | ColumnIndex | Gets the column index of the cell that the event occurs for. (Inherited from DataGridViewCellCancelEventArgs.) |
![]() | Context | Gets details about the state of the DataGridView when the error occurred. |
![]() | Exception | Gets the exception that represents the error. |
![]() | RowIndex | Gets the row index of the cell that the event occurs for. (Inherited from DataGridViewCellCancelEventArgs.) |
![]() | ThrowException | Gets or sets a value indicating whether to throw the exception after the DataGridViewDataErrorEventHandler delegate is finished with it. |
| Name | Description | |
|---|---|---|
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
Handling the DataError event lets you handle exceptions thrown by code outside your control (for example, by an external data source). Use the Context property to determine the state of the DataGridView at the time of the exception. Use the Exception property to retrieve the exception data. If you want to handle the exception by additional event handlers, set the ThrowException property to true.
The ColumnIndex and RowIndex properties normally indicate the cell in which the data error occurred. When the error occurs in an external data source, however, the data source may not provide the column in which the error occurred. In this case, the ColumnIndex property typically indicates the column of the current cell at the time of the error.
The following code example demonstrates how to respond to information provided by the DataGridViewDataErrorEventArgs class. This example is part of a larger example available in the DataGridViewComboBoxColumn class overview topic.
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; } }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
