DataGridView.CurrentCellDirtyStateChanged Zdarzenie

Definicja

Występuje, gdy stan komórki zmienia się w odniesieniu do zmiany jego zawartości.

public:
 event EventHandler ^ CurrentCellDirtyStateChanged;
public event EventHandler CurrentCellDirtyStateChanged;
public event EventHandler? CurrentCellDirtyStateChanged;
member this.CurrentCellDirtyStateChanged : EventHandler 
Public Custom Event CurrentCellDirtyStateChanged As EventHandler 

Typ zdarzenia

Przykłady

W poniższym przykładzie kodu pokazano, jak obsłużyć CurrentCellDirtyStateChanged zdarzenie. W tym przykładzie program obsługi zdarzeń wywołuje metodę CommitEditCellValueChanged , aby zgłosić zdarzenie i określić bieżącą wartość elementu DataGridViewCheckBoxCell. Ten przykład kodu jest częścią większego przykładu przedstawionego w temacie How to: Disable Buttons in a Button Column in the Windows Forms DataGridView Control (Jak wyłączyć przyciski w kolumnie przycisku w kontrolce 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();
    }
}
' This event handler manually raises the CellValueChanged event
' by calling the CommitEdit method.
Sub dataGridView1_CurrentCellDirtyStateChanged( _
    ByVal sender As Object, ByVal e As EventArgs) _
    Handles dataGridView1.CurrentCellDirtyStateChanged

    If dataGridView1.IsCurrentCellDirty Then
        dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit)
    End If
End Sub

' If a check box cell is clicked, this event handler disables  
' or enables the button in the same row as the clicked cell.
Public Sub dataGridView1_CellValueChanged(ByVal sender As Object, _
    ByVal e As DataGridViewCellEventArgs) _
    Handles dataGridView1.CellValueChanged

    If dataGridView1.Columns(e.ColumnIndex).Name = "CheckBoxes" Then
        Dim buttonCell As DataGridViewDisableButtonCell = _
            CType(dataGridView1.Rows(e.RowIndex).Cells("Buttons"), _
            DataGridViewDisableButtonCell)

        Dim checkCell As DataGridViewCheckBoxCell = _
            CType(dataGridView1.Rows(e.RowIndex).Cells("CheckBoxes"), _
            DataGridViewCheckBoxCell)
        buttonCell.Enabled = Not CType(checkCell.Value, [Boolean])

        dataGridView1.Invalidate()
    End If
End Sub

Uwagi

Komórka jest oznaczona jako zmodyfikowana, jeśli jego zawartość została zmieniona, ale zmiana nie została zapisana.

To zdarzenie zwykle występuje, gdy komórka została edytowana, ale zmiana nie została zatwierdzona w pamięci podręcznej danych lub gdy operacja edycji zostanie anulowana.

Aby uzyskać więcej informacji na temat obsługi zdarzeń, zobacz Obsługa i podnoszenie zdarzeń.

Dotyczy

Zobacz też