Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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 */
public boolean get_ThrowException ()

/** @property */
public void set_ThrowException (boolean value)

public function get ThrowException () : boolean

public function set ThrowException (value : boolean)

Not applicable.

Property Value

true if the exception should be thrown; otherwise, false. The default is false.

Exception typeCondition

ArgumentException

When setting this property to true, the Exception property value is a null reference (Nothing in Visual Basic).

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;
    }
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

Show:
© 2014 Microsoft