DataGridView.NotifyCurrentCellDirty(Boolean) 方法

定义

通知 DataGridView 当前单元格有未提交的更改。Notifies the DataGridView that the current cell has uncommitted changes.

public:
 virtual void NotifyCurrentCellDirty(bool dirty);
public virtual void NotifyCurrentCellDirty (bool dirty);
abstract member NotifyCurrentCellDirty : bool -> unit
override this.NotifyCurrentCellDirty : bool -> unit
Public Overridable Sub NotifyCurrentCellDirty (dirty As Boolean)

参数

dirty
Boolean

如果要指示该单元格有未提交的更改,为 true;否则为 falsetrue to indicate the cell has uncommitted changes; otherwise, false.

示例

下面的代码示例演示如何在自定义单元格方案中使用此方法。The following code example illustrates the use of this method in a custom cell scenario. 在此示例中,派生自 DateTimePicker 类的 IDataGridViewEditingControl 实现将重写 OnValueChanged 方法,并使用 NotifyCurrentCellDirty 方法指示对 DataGridView 控件的更改。In the example, an IDataGridViewEditingControl implementation derived from the DateTimePicker class overrides the OnValueChanged method and uses the NotifyCurrentCellDirty method to indicate a change to the DataGridView control.

此示例是如何:在 Windows 窗体 DataGridView 单元格中承载控件中所示的一个更大示例的一部分。This example is part of a larger example shown in How to: Host Controls in Windows Forms DataGridView Cells.

protected override void OnValueChanged(EventArgs eventargs)
{
    // Notify the DataGridView that the contents of the cell
    // have changed.
    valueChanged = true;
    this.EditingControlDataGridView.NotifyCurrentCellDirty(true);
    base.OnValueChanged(eventargs);
}
Protected Overrides Sub OnValueChanged(ByVal eventargs As EventArgs)

    ' Notify the DataGridView that the contents of the cell have changed.
    valueIsChanged = True
    Me.EditingControlDataGridView.NotifyCurrentCellDirty(True)
    MyBase.OnValueChanged(eventargs)

End Sub

注解

此方法可用于允许自定义单元格类型在有未提交的更改时通知 DataGridViewThis method can be used to allow custom cell types to notify the DataGridView when they have uncommitted changes.

适用于

另请参阅