DataGridView.CellEndEdit Événement

Définition

Se produit lorsque le mode édition est arrêté pour la cellule actuellement sélectionnée.

public:
 event System::Windows::Forms::DataGridViewCellEventHandler ^ CellEndEdit;
public event System.Windows.Forms.DataGridViewCellEventHandler CellEndEdit;
public event System.Windows.Forms.DataGridViewCellEventHandler? CellEndEdit;
member this.CellEndEdit : System.Windows.Forms.DataGridViewCellEventHandler 
Public Custom Event CellEndEdit As DataGridViewCellEventHandler 

Type d'événement

Exemples

L’exemple de code suivant montre comment gérer cet événement pour effacer la propriété de ligne DataGridViewRow.ErrorText au cas où elle était précédemment définie par un gestionnaire d’événements CellValidating . Le CellValidating gestionnaire d’événements peut effacer le texte d’erreur lorsque la nouvelle valeur de cellule répond aux critères de validation, mais lorsque l’utilisateur revient à l’ancienne valeur de cellule en appuyant sur Échap, l’événement CellValidating ne se produit pas. Cet exemple fait partie d’un exemple plus large disponible dans Procédure pas à pas : validation des données dans le contrôle DataGridView Windows Forms.

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;
}
Private Sub dataGridView1_CellValidating(ByVal sender As Object, _
    ByVal e As DataGridViewCellValidatingEventArgs) _
    Handles dataGridView1.CellValidating

    Dim headerText As String = _
        dataGridView1.Columns(e.ColumnIndex).HeaderText

    ' 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

Remarques

Pour plus d’informations sur la façon de gérer les événements, consultez gestion et déclenchement d’événements.

S’applique à

Voir aussi