Export (0) Print
Expand All
Expand Minimize

DataGridView.CellEndEdit Event

Occurs when edit mode stops for the currently selected cell.

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

public event DataGridViewCellEventHandler CellEndEdit

For more information about handling events, see Consuming Events.

The following code example illustrates how to handle this event to clear the row DataGridViewRow.ErrorText property in case it was previously set by a CellValidating event handler. The CellValidating event handler can clear the error text when the new cell value meets the validation criteria, but when the user reverts to the old cell value by pressing ESC, the CellValidating event does not occur. This example is part of a larger example available in Walkthrough: Validating Data in the Windows Forms DataGridView Control.

private void dataGridView1_CellValidating(object sender,
    DataGridViewCellValidatingEventArgs e)
{
    string headerText = 
        dataGridView1.Columns[e.ColumnIndex].HeaderText;

    // Abort validation if cell is not in the CompanyName column. 
    if (!headerText.Equals("CompanyName")) return;

    // Confirm that the cell is not empty. 
    if (string.IsNullOrEmpty(e.FormattedValue.ToString()))
    {
        dataGridView1.Rows[e.RowIndex].ErrorText =
            "Company Name must not be empty";
        e.Cancel = true;
    }
}

void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
    // Clear the row error in case the user presses ESC.   
    dataGridView1.Rows[e.RowIndex].ErrorText = String.Empty;
}

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft