DataGridView.CommitEdit(DataGridViewDataErrorContexts) 메서드

정의

편집 모드를 끝내지 않고 현재 셀의 변경 내용을 데이터 캐시에 커밋합니다.

public:
 bool CommitEdit(System::Windows::Forms::DataGridViewDataErrorContexts context);
public bool CommitEdit (System.Windows.Forms.DataGridViewDataErrorContexts context);
member this.CommitEdit : System.Windows.Forms.DataGridViewDataErrorContexts -> bool
Public Function CommitEdit (context As DataGridViewDataErrorContexts) As Boolean

매개 변수

context
DataGridViewDataErrorContexts

오류 발생 가능한 컨텍스트를 지정하는 DataGridViewDataErrorContexts 값의 비트 조합입니다.

반환

변경 내용이 커밋되었으면 true이고, 그렇지 않으면 false입니다.

예외

셀 값을 커밋할 수 없으며 DataError 이벤트에 대한 처리기가 없거나 처리기의 ThrowException 속성이 true로 설정되어 있습니다.

예제

다음 코드 예제에서는 이벤트 처리기 내에서 메서드를 CurrentCellDirtyStateChanged 호출 CommitEdit 하여 이벤트를 발생합니다CellValueChanged. 이 코드 예제는 방법: 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

설명

이 메서드는 서식이 지정된 사용자 지정 값을 기본 셀 데이터 형식으로 변환하려고 시도합니다. 이렇게 하려면 형식 변환을 CellParsing 사용자 지정하기 위해 처리할 수 있는 이벤트가 발생합니다. 그렇지 않으면 기본 형식 변환기가 사용됩니다. 이벤트를 방지하기 위해 처리되지 않은 경우 DataError 변환 오류로 인해 예외가 발생할 수 있습니다. 값이 성공적으로 변환되면 데이터 저장소에 커밋되어 속성 값이 일 때 데이터 바인딩되지 않은 셀에 VirtualMode 대한 이벤트가 발생 CellValuePushed 합니다true. 값이 성공적으로 커밋 CellValueChanged 되면 이벤트가 발생합니다.

적용 대상

추가 정보