DataGridView.IsCurrentCellDirty DataGridView.IsCurrentCellDirty DataGridView.IsCurrentCellDirty DataGridView.IsCurrentCellDirty Property

定義

取得值,指出目前的儲存格是否有未經認可的變更。Gets a value indicating whether the current cell has uncommitted changes.

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

屬性值

如果目前的儲存格有未經認可的變更,則為 true;否則為 falsetrue if the current cell has uncommitted changes; otherwise, false.

範例

下列程式碼範例會使用IsCurrentCellDirty屬性來判斷是否要認可儲存格值,並CurrentCellDirtyStateChanged從事件CellValueChanged的處理常式引發事件。The following code example uses the IsCurrentCellDirty property to determine whether to commit a cell value and raise the CellValueChanged event from a handler for the CurrentCellDirtyStateChanged event. 這個程式碼範例是如何:停用 Windows Forms DataGridView 控制項中按鈕資料行的按鈕。This code example is part of a larger example provided in 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當未系結至資料時,當使用者移至另一個儲存格時,儲存格編輯會被視為已認可。When the DataGridView is not bound to data, the cell edit is considered committed when the user moves to another cell.

如果資料列標頭可見,則包含有未認可變更之儲存格的資料列標頭中會有鉛筆圖像。If row headers are visible, a pencil glyph is present in the header for the row that contains a cell with uncommitted changes.

如果IsCurrentCellDirty EditingControltrue ,而且目前的儲存格主控編輯控制項,您可以透過屬性抓取它。If IsCurrentCellDirty is true and the current cell hosts an editing control, you can retrieve it through the EditingControl property.

適用於

另請參閱