ErrorText Property
Collapse the table of content
Expand the table of content

DataGridViewRowErrorTextNeededEventArgs.ErrorText Property

Gets or sets the error text for the row.

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

public string ErrorText { get; set; }

Property Value

Type: System.String
A string that represents the error text for the row.

This property initially contains the value of the DataGridViewRow.ErrorText property if it has been set for a row.

The ErrorText property value displays as a ToolTip for the error glyph in the row header.

The following code example demonstrates how to use the ErrorText property in an event handler. Although the code actually uses the DataGridViewCellErrorTextNeededEventArgs.ErrorText property, this property is nearly identical to the ErrorText property of DataGridViewRowErrorTextNeededEventArgs.

private ToolStripMenuItem wholeTable = new ToolStripMenuItem();
private ToolStripMenuItem lookUp = new ToolStripMenuItem();
private ContextMenuStrip strip;
private string cellErrorText;

private void dataGridView1_CellContextMenuStripNeeded(object sender,
    DataGridViewCellContextMenuStripNeededEventArgs e)
    cellErrorText = String.Empty;

    if (strip == null)
        strip = new ContextMenuStrip();
        lookUp.Text = "Look Up";
        wholeTable.Text = "See Whole Table";
    e.ContextMenuStrip = strip;

private void wholeTable_Click(object sender, EventArgs e)
    dataGridView1.DataSource = Populate("Select * from employees", true);

private DataGridViewCellEventArgs theCellImHoveringOver;

private void dataGridView1_CellMouseEnter(object sender, DataGridViewCellEventArgs e)
    theCellImHoveringOver = e;

private DataGridViewCellEventArgs cellErrorLocation;

private void lookUp_Click(object sender, EventArgs e)
        dataGridView1.DataSource = Populate("Select * from employees where " +
            dataGridView1.Columns[theCellImHoveringOver.ColumnIndex].Name + " = '" +
            Cells[theCellImHoveringOver.ColumnIndex].Value + "'",
    catch (SqlException)
        cellErrorText = "Can't look this cell up";
        cellErrorLocation = theCellImHoveringOver;

private void dataGridView1_CellErrorTextNeeded(object sender,
    DataGridViewCellErrorTextNeededEventArgs e)
    if (cellErrorLocation != null)
        if (e.ColumnIndex == cellErrorLocation.ColumnIndex &&
            e.RowIndex == cellErrorLocation.RowIndex)
            e.ErrorText = cellErrorText;

private DataTable Populate(string query, bool resetUnsharedCounter)
    if (resetUnsharedCounter)

    // Alter the data source as necessary
    SqlDataAdapter adapter = new SqlDataAdapter(query,
        new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;" +
        "Initial Catalog=Northwind;Data Source=localhost"));

    DataTable table = new DataTable();
    table.Locale = System.Globalization.CultureInfo.InvariantCulture;
    return table;

private Label count = new Label();
private int unsharedRowCounter;

private void ResetCounter()
    unsharedRowCounter = 0;
    count.Text = unsharedRowCounter.ToString();

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

© 2015 Microsoft