DataGridView.CurrentCellDirtyStateChanged DataGridView.CurrentCellDirtyStateChanged DataGridView.CurrentCellDirtyStateChanged DataGridView.CurrentCellDirtyStateChanged Event

定義

セルの内容の変更に関連して、セルの状態が変更するときに発生します。Occurs when the state of a cell changes in relation to a change in its contents.

public:
 event EventHandler ^ CurrentCellDirtyStateChanged;
public event EventHandler CurrentCellDirtyStateChanged;
member this.CurrentCellDirtyStateChanged : EventHandler 
Public Custom Event CurrentCellDirtyStateChanged As EventHandler 

CurrentCellDirtyStateChangedイベントを処理する方法を次のコード例に示します。The following code example demonstrates how to handle the CurrentCellDirtyStateChanged event. この例では、イベントハンドラーはCommitEditメソッドを呼び出して、 CellValueChangedイベントを発生させ、の現在のDataGridViewCheckBoxCell値を確認します。In this example, the event handler calls the CommitEdit method to raise the CellValueChanged event and determine the current value of a DataGridViewCheckBoxCell. このコード例は、次の方法で提供される大規模な例の一部です。Windows フォーム 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

注釈

セルの内容が変更されていても、変更が保存されていない場合は、変更済みとしてマークされます。A cell is marked as modified if its contents have changed but the change has not been saved.

このイベントは、通常、セルが編集されていても、変更がデータキャッシュにコミットされていない場合、または編集操作が取り消された場合に発生します。This event typically occurs when a cell has been edited but the change has not been committed to the data cache, or when an edit operation is canceled.

イベントを処理する方法の詳細については、次を参照してください。処理とイベントの発生します。For more information about how to handle events, see Handling and Raising Events.

適用対象

こちらもご覧ください