This documentation is archived and is not being maintained.

DataGridViewRow.ErrorText Property

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

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public string ErrorText { get; set; }
/** @property */
public String get_ErrorText ()

/** @property */
public void set_ErrorText (String value)

public function get ErrorText () : String

public function set ErrorText (value : String)

Not applicable.

Property Value

A String containing the error message.

Exception typeCondition

InvalidOperationException

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

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.

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

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.

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
Show: