Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ThrowException Property
Collapse the table of content
Expand the table of content

DataGridViewDataErrorEventArgs.ThrowException Property

Gets or sets a value indicating whether to throw the exception after the DataGridViewDataErrorEventHandler delegate is finished with it.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public bool ThrowException { get; set; }

Property Value

Type: System.Boolean
true if the exception should be thrown; otherwise, false. The default is false.

ExceptionCondition
ArgumentException

When setting this property to true, the Exception property value is null.

Set this property to false if the DataGridViewDataErrorEventHandler has dealt with the exception represented by the Exception property, and you do not want to propagate the exception to another DataGridViewDataErrorEventHandler that may handle the DataError event.

For debugging purposes, it can be useful to propagate the exception and inspect the stack trace for information regarding the context of the error.

The following code example demonstrates using the ThrowException property to indicate that the exception should not be thrown. 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 ((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;
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft