DataGridView.CurrentCellDirtyStateChanged 이벤트

정의

셀의 내용이 변경되어 셀의 상태가 변경될 때 발생합니다.

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

이벤트 유형

예제

다음 코드 예제에서는 처리 하는 방법에 설명 합니다 CurrentCellDirtyStateChanged 이벤트입니다. 이 예제에서 이벤트 처리기는 메서드를 CommitEdit 호출하여 이벤트를 발생 CellValueChanged 시키고 의 DataGridViewCheckBoxCell현재 값을 확인합니다. 이 코드 예제는 방법: Windows Forms DataGridView 컨트롤의 단추 열에서 단추 사용 안 함에서 제공하는 더 큰 예제의 일부입니다.

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

설명

내용이 변경되었지만 변경 내용이 저장되지 않은 경우 셀이 수정된 것으로 표시됩니다.

이 이벤트는 일반적으로 셀이 편집되었지만 변경 내용이 데이터 캐시에 커밋되지 않았거나 편집 작업이 취소될 때 발생합니다.

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.

적용 대상

추가 정보