DataGridView.IsCurrentCellDirty 属性

定义

获取一个值,该值指示当前单元格是否有未提交的更改。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 属性来确定是否提交单元值并从 @no__t 2 事件的处理程序引发 @no__t 1 事件。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. 此代码示例摘自 [How 中提供的一个更大的示例:禁用 Windows 窗体 DataGridView 控件 @ no__t 中的按钮列中的按钮。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

注解

如果 @no__t 0 未绑定到数据,则当用户移到另一个单元格时,会将单元格编辑视为已提交。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 @no__t 为-1,当前单元格承载编辑控件,则可以通过 @no__t 的属性进行检索。If IsCurrentCellDirty is true and the current cell hosts an editing control, you can retrieve it through the EditingControl property.

适用于

另请参阅