DataGridView.ProcessDataGridViewKey(KeyEventArgs) 메서드

정의

DataGridView에서 이동하는 데 사용되는 키를 처리합니다.

protected:
 virtual bool ProcessDataGridViewKey(System::Windows::Forms::KeyEventArgs ^ e);
protected virtual bool ProcessDataGridViewKey (System.Windows.Forms.KeyEventArgs e);
abstract member ProcessDataGridViewKey : System.Windows.Forms.KeyEventArgs -> bool
override this.ProcessDataGridViewKey : System.Windows.Forms.KeyEventArgs -> bool
Protected Overridable Function ProcessDataGridViewKey (e As KeyEventArgs) As Boolean

매개 변수

e
KeyEventArgs

누른 키에 대한 정보가 들어 있습니다.

반환

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

예외

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

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

또는

DELETE 키를 누르면 하나 이상의 행이 삭제되지만, 데이터 소스의 오류로 인해 삭제되지 않으며 DataError 이벤트용 처리기가 없거나 처리기에서 ThrowException 속성을 true로 설정했습니다.

예제

다음 코드 예제에서는 및 메서드를 재정의 하 여 하위 클래스에서 DataGridView ENTER 키의 동작을 변경 하는 ProcessDataGridViewKeyProcessDialogKey 방법을 보여 줍니다. 이 예제에서 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

설명

이 메서드는 눌렀던 키(예 ProcessF2Key : F2를 누를 때 메서드)에 적합한 키 처리 메서드를 호출하고 해당 메서드의 반환 값을 반환합니다.

상속자 참고

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

적용 대상

추가 정보