DataGridView.ProcessDialogKey(Keys) 메서드

정의

대화 상자를 제어하는 데 사용되는 Tab, Esc, Enter, 화살표 키 등의 키를 처리합니다.

protected:
 override bool ProcessDialogKey(System::Windows::Forms::Keys keyData);
protected override bool ProcessDialogKey (System.Windows.Forms.Keys keyData);
override this.ProcessDialogKey : System.Windows.Forms.Keys -> bool
Protected Overrides Function ProcessDialogKey (keyData As Keys) As Boolean

매개 변수

keyData
Keys

처리할 키를 하나 이상 나타내는 Keys 값의 비트 조합입니다.

반환

해당 키가 처리되었으면 true이고, 그렇지 않으면 false입니다.

예외

누른 키로 인해 컨트롤이 편집 모드로 들어가지만 현재 셀의 EditType 속성이 Control에서 파생되어 IDataGridViewEditingControl을 구현하는 클래스를 나타내지 않는 경우

이 작업을 수행하면 셀 값이 커밋되거나 편집 모드로 전환되지만 데이터 소스의 오류 때문에 해당 작업이 수행되지 않으며 DataError 이벤트에 대한 처리기가 없거나 처리기가 ThrowException 속성을 true로 설정했습니다.

예제

다음 코드 예제에서는 재정의 하 여 하위 클래스에서 ENTER 키의 동작을 DataGridView 변경 하는 ProcessDataGridViewKey 방법을 보여 줍니다는 및 ProcessDialogKey 메서드. 이 예제에서 ENTER 키는 오른쪽 화살표 키와 동일한 동작을 하므로 사용자가 한 행의 데이터에서 여러 셀을 더 쉽게 편집할 수 있습니다.

public class CustomDataGridView : DataGridView
{
    protected override bool ProcessDialogKey(Keys keyData)
    {
        // Extract the key code from the key value. 
        Keys key = (keyData & Keys.KeyCode);

        // Handle the ENTER key as if it were a RIGHT ARROW key. 
        if (key == Keys.Enter)
        {
            return this.ProcessRightKey(keyData);
        }
        return base.ProcessDialogKey(keyData);
    }

    protected override bool ProcessDataGridViewKey(KeyEventArgs e)
    {
        // Handle the ENTER key as if it were a RIGHT ARROW key. 
        if (e.KeyCode == Keys.Enter)
        {
            return this.ProcessRightKey(e.KeyData);
        }
        return base.ProcessDataGridViewKey(e);
    }
}
Public Class CustomDataGridView
    Inherits DataGridView

    <System.Security.Permissions.UIPermission( _
        System.Security.Permissions.SecurityAction.LinkDemand, _
        Window:=System.Security.Permissions.UIPermissionWindow.AllWindows)> _
    Protected Overrides Function ProcessDialogKey( _
        ByVal keyData As Keys) As Boolean

        ' Extract the key code from the key value. 
        Dim key As Keys = keyData And Keys.KeyCode

        ' Handle the ENTER key as if it were a RIGHT ARROW key. 
        If key = Keys.Enter Then
            Return Me.ProcessRightKey(keyData)
        End If

        Return MyBase.ProcessDialogKey(keyData)

    End Function

    <System.Security.Permissions.SecurityPermission( _
        System.Security.Permissions.SecurityAction.LinkDemand, Flags:= _
        System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)> _
    Protected Overrides Function ProcessDataGridViewKey( _
        ByVal e As System.Windows.Forms.KeyEventArgs) As Boolean

        ' Handle the ENTER key as if it were a RIGHT ARROW key. 
        If e.KeyCode = Keys.Enter Then
            Return Me.ProcessRightKey(e.KeyData)
        End If

        Return MyBase.ProcessDataGridViewKey(e)

    End Function

End Class

설명

이 메서드는 호스트된 편집 컨트롤에서 처리되지 않는 키보드 입력을 처리하기 위해 편집 모드에서 호출됩니다.

키 누름이 입력 키가 아닌 것으로 확인되면 처리를 위해 기본 클래스로 전송됩니다.

상속자 참고

이 메서드를 재정의할 때 컨트롤은 키를 처리했음을 나타내기 위해 반환 true 되어야 합니다. 컨트롤에서 처리되지 않는 키의 경우 이 메서드의 기본 버전 결과를 반환합니다.

적용 대상

추가 정보