DataGridView.IsCurrentCellDirty Proprietà

Definizione

Ottiene un valore che indica se sono presenti modifiche non salvate per la cella corrente.

public:
 property bool IsCurrentCellDirty { bool get(); };
[System.ComponentModel.Browsable(false)]
public bool IsCurrentCellDirty { get; }
[<System.ComponentModel.Browsable(false)>]
member this.IsCurrentCellDirty : bool
Public ReadOnly Property IsCurrentCellDirty As Boolean

Valore della proprietà

true se sono presenti modifiche non salvate per la cella corrente; in caso contrario, false.

Attributi

Esempio

Nell'esempio di codice seguente viene utilizzata la IsCurrentCellDirty proprietà per determinare se eseguire il commit di un valore di cella e generare l'evento CellValueChanged da un gestore per l'evento CurrentCellDirtyStateChanged . Questo esempio di codice fa parte di un esempio più ampio fornito in Procedura: Disabilitare i pulsanti in una colonna button nel controllo DataGridView Windows Forms.

// 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

Commenti

Quando l'oggetto DataGridView non è associato ai dati, la modifica della cella viene considerata sottoposta a commit quando l'utente passa a un'altra cella.

Se le intestazioni di riga sono visibili, un glifo della matita è presente nell'intestazione per la riga che contiene una cella con modifiche di cui non è stato eseguito il commit.

Se IsCurrentCellDirty è true e la cella corrente ospita un controllo di modifica, è possibile recuperarla tramite la EditingControl proprietà .

Si applica a

Vedi anche