共用方式為


DataGridView.IsCurrentCellDirty 屬性

定義

取得值,指出目前的儲存格是否有未經認可的變更。

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

屬性值

如果目前的儲存格有未經認可的變更,則為 true;否則為 false

屬性

範例

下列程式碼範例會 IsCurrentCellDirty 使用 屬性來判斷是否認可儲存格值,並從事件的處理常式 CurrentCellDirtyStateChanged 引發 CellValueChanged 事件。 此程式碼範例是How to: Disable Buttons in a Button Column in the Windows Forms DataGridView Control中提供之較大範例的一部分。

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

備註

DataGridView當 未系結至資料時,當使用者移至另一個儲存格時,會將儲存格編輯視為已認可。

如果可以看到資料列標題,則含有未認可變更之儲存格的資料列標頭中會出現鉛筆圖像。

如果 IsCurrentCellDirtytrue 且目前的儲存格裝載編輯控制項,您可以透過 EditingControl 屬性擷取它。

適用於

另請參閱