DataGridView.ProcessRightKey(Keys) Método

Definición

Procesa la tecla de dirección DERECHA.

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

Parámetros

keyData
Keys

Combinación bit a bit de valores de Keys que representa las teclas que se van a procesar.

Devoluciones

Es true si la tecla se procesó; en caso contrario, es false.

Excepciones

La tecla FLECHA DERECHA provocaría que el control accediese al modo de edición, pero la propiedad EditType de la nueva celda actual no indica una clase derivada de Control e implementa IDataGridViewEditingControl.

Esta acción podría confirmar un valor de celda o provocar el acceso al modo de edición, pero un error en el origen de datos impide la acción y no hay ningún controlador para el evento DataError o el controlador estableció la propiedad ThrowException en true.

Ejemplos

En el ejemplo de código siguiente se muestra cómo cambiar el comportamiento de la clave ENTER en una DataGridView subclase reemplazando los ProcessDataGridViewKey métodos y ProcessDialogKey . En el ejemplo, la tecla ENTRAR tiene el mismo comportamiento que la tecla FLECHA DERECHA, lo que facilita a un usuario editar varias celdas en una sola fila de datos.

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

Se aplica a

Consulte también