DataGridView.ProcessRightKey(Keys) メソッド

定義

→キーを処理します。

protected:
 bool ProcessRightKey(System::Windows::Forms::Keys keyData);
protected bool ProcessRightKey(System.Windows.Forms.Keys keyData);
member this.ProcessRightKey : System.Windows.Forms.Keys -> bool
Protected Function ProcessRightKey (keyData As Keys) As Boolean

パラメーター

keyData
Keys

処理するキーを表す Keys 値のビットごとの組み合わせ。

返品

true キーが処理された場合。それ以外の場合は false

例外

右方向キーを押すとコントロールは編集モードになりますが、新しい現在のセルの EditType プロパティは、 Control から派生し、 IDataGridViewEditingControlを実装するクラスを示していません。

このアクションはセル値をコミットするか編集モードに入りますが、データ ソースのエラーによってアクションが妨げられます。また、 DataError イベントのハンドラーが存在しないか、ハンドラーによって ThrowException プロパティが trueに設定されています。

次のコード例では、ProcessDataGridViewKey メソッドと ProcessDialogKey メソッドをオーバーライドして、DataGridView サブクラスの ENTER キーの動作を変更する方法を示します。 この例では、ENTER キーの動作は右方向キーと同じであるため、ユーザーは 1 行のデータ内の複数のセルを簡単に編集できます。

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

適用対象

こちらもご覧ください