DataGridViewDataErrorEventArgs::Exception Property
.NET Framework (current version)
Gets the exception that represents the error.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
To handle the exception by more than one DataGridViewDataErrorEventHandler, throw the exception again at the end of a handler by setting the ThrowException property to true.
The following code example demonstrates checking the Exception property. 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; } }
.NET Framework
Available since 2.0
Available since 2.0
Show: