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 CellEndEdit As DataGridViewCellEventHandler

For more information about handling events, see NIB: 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 Sub dataGridView1_CellValidating(ByVal sender As Object, _
    ByVal e As DataGridViewCellValidatingEventArgs) _
    Handles dataGridView1.CellValidating

    Dim headerText As String = _

    ' Abort validation if cell is not in the CompanyName column.
    If Not headerText.Equals("CompanyName") Then Return

    ' Confirm that the cell is not empty.
    If (String.IsNullOrEmpty(e.FormattedValue.ToString())) Then
        dataGridView1.Rows(e.RowIndex).ErrorText = _
            "Company Name must not be empty"
        e.Cancel = True
    End If
End Sub

Private Sub dataGridView1_CellEndEdit(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
    Handles dataGridView1.CellEndEdit

    ' Clear the row error in case the user presses ESC.   
    dataGridView1.Rows(e.RowIndex).ErrorText = String.Empty

End Sub

.NET Framework
Available since 2.0
Return to top