DataGridView.BeginEdit(Boolean) 메서드

정의

현재 셀을 편집 모드로 전환합니다.

public:
 virtual bool BeginEdit(bool selectAll);
public virtual bool BeginEdit (bool selectAll);
abstract member BeginEdit : bool -> bool
override this.BeginEdit : bool -> bool
Public Overridable Function BeginEdit (selectAll As Boolean) As Boolean

매개 변수

selectAll
Boolean

모든 셀의 내용을 선택하려면 true이고, 아무 내용도 선택하지 않으려면 false입니다.

반환

현재 셀이 이미 편집 모드에 있거나 성공적으로 편집 모드로 전환되었으면 true이고, 그렇지 않으면 false입니다.

예외

CurrentCell이 유효한 셀로 설정되지 않았습니다.

또는

이 메서드가 CellBeginEdit 이벤트의 처리기에서 호출되었습니다.

셀의 EditType 속성이 나타내는 형식이 Control 형식에서 파생되지 않습니다.

또는

셀의 EditType 속성이 나타내는 형식이 IDataGridViewEditingControl 인터페이스를 구현하지 않습니다.

편집 셀 값을 초기화하지 못했으며 DataError 이벤트에 대한 처리기가 없거나 처리기의 ThrowException 속성이 true로 설정되어 있습니다. 예외 개체는 일반적으로 FormatException 형식으로 캐스팅할 수 있습니다.

예제

다음 코드 예제에서는이 메서드를 사용 하는 방법을 보여 줍니다.

// Override OnMouseClick in a class derived from DataGridViewCell to 
// enter edit mode when the user clicks the cell. 
protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
{
    if (base.DataGridView != null)
    {
        Point point1 = base.DataGridView.CurrentCellAddress;
        if (point1.X == e.ColumnIndex &&
            point1.Y == e.RowIndex &&
            e.Button == MouseButtons.Left &&
            base.DataGridView.EditMode !=
            DataGridViewEditMode.EditProgrammatically)
        {
            base.DataGridView.BeginEdit(true);
        }
    }
}
' Override OnMouseClick in a class derived from DataGridViewCell to 
' enter edit mode when the user clicks the cell. 
Protected Overrides Sub OnMouseClick( _
    ByVal e As DataGridViewCellMouseEventArgs)

    If MyBase.DataGridView IsNot Nothing Then

        Dim point1 As Point = MyBase.DataGridView.CurrentCellAddress
        If point1.X = e.ColumnIndex And _
            point1.Y = e.RowIndex And _
            e.Button = MouseButtons.Left And _
            Not MyBase.DataGridView.EditMode = _
            DataGridViewEditMode.EditProgrammatically Then

            MyBase.DataGridView.BeginEdit(True)

        End If
    End If
End Sub

설명

이 메서드는 셀이 편집 모드로 전환되지 않는 경우 를 반환 false 하며, 이는 여러 가지 이유로 발생할 수 있습니다. 이 메서드는 현재 셀이 읽기 전용인 경우 를 반환 false 합니다. 또한 셀 속성이 null 이고(셀 EditType 이 편집 컨트롤을 호스트할 수 없음) 셀 형식이 인터페이스를 구현 IDataGridViewEditingCell 하지 않는 경우에도 반환 false 됩니다.

셀이 편집을 지원하는 경우 이 메서드는 취소할 수 있는 이벤트를 발생 CellBeginEdit 시키고 이벤트 처리기가 편집을 취소하면 를 반환 false 합니다. 편집이 취소되지 않고 셀에서 편집 컨트롤을 호스트할 수 있는 경우 이 메서드는 컨트롤을 초기화하고 표시합니다. 초기화에 실패하면 이 메서드는 를 반환합니다 false.

셀이 편집 모드로 전환되면 속성은 를 IsCurrentCellInEditMode 반환합니다 true.

적용 대상

추가 정보