Lire en anglais

Partager via


DataGridView.CurrentCellDirtyStateChanged Événement

Définition

Se produit quand l’état d’une cellule change en relation avec une modification de son contenu.

public event EventHandler CurrentCellDirtyStateChanged;
public event EventHandler? CurrentCellDirtyStateChanged;

Type d'événement

Exemples

L’exemple de code suivant montre comment gérer l’événement CurrentCellDirtyStateChanged . Dans cet exemple, le gestionnaire d’événements appelle la CommitEdit méthode pour déclencher l’événement CellValueChanged et déterminer la valeur actuelle d’un DataGridViewCheckBoxCell. Cet exemple de code fait partie d’un exemple plus large fourni dans How to: Disable Button Column in a Button Column in the Windows Forms Contrôle DataGridView.

// This event handler manually raises the CellValueChanged event
// by calling the CommitEdit method.
void dataGridView1_CurrentCellDirtyStateChanged(object sender,
    EventArgs e)
{
    if (dataGridView1.IsCurrentCellDirty)
    {
        dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
    }
}

// If a check box cell is clicked, this event handler disables  
// or enables the button in the same row as the clicked cell.
public void dataGridView1_CellValueChanged(object sender,
    DataGridViewCellEventArgs e)
{
    if (dataGridView1.Columns[e.ColumnIndex].Name == "CheckBoxes")
    {
        DataGridViewDisableButtonCell buttonCell =
            (DataGridViewDisableButtonCell)dataGridView1.
            Rows[e.RowIndex].Cells["Buttons"];

        DataGridViewCheckBoxCell checkCell =
            (DataGridViewCheckBoxCell)dataGridView1.
            Rows[e.RowIndex].Cells["CheckBoxes"];
        buttonCell.Enabled = !(Boolean)checkCell.Value;

        dataGridView1.Invalidate();
    }
}

Remarques

Une cellule est marquée comme modifiée si son contenu a changé, mais que la modification n’a pas été enregistrée.

Cet événement se produit généralement lorsqu’une cellule a été modifiée, mais que la modification n’a pas été validée dans le cache de données, ou lorsqu’une opération de modification est annulée.

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

S’applique à

Produit Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

Voir aussi