DataGridViewRow.ErrorText Property

Definition

Gets or sets the error message text for row-level errors.

C#
public string ErrorText { get; set; }

Property Value

A String containing the error message.

Exceptions

When getting the value of this property, the row is a shared row in a DataGridView control.

Examples

The following code example demonstrates how to use the ErrorText property in a DataError event handler. This example is part of a larger example available in the DataGridViewComboBoxColumn class overview.

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

Remarks

Use this property to provide an error message for row-level errors. The specified message is displayed in a ToolTip when the user moves the mouse pointer over the error icon shown in the row header.

Starting with the .NET Framework 4.5.2, the error icon is resized according to the system DPI setting when the app.config file contains the following entry:

<appSettings>
  <add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
</appSettings>

If this row is associated with a DataGridView control, setting this property will raise the RowErrorTextChanged event.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also