DataGridView.ProcessRightKey(Keys) Método

Definição

Processa a tecla SETA PARA A DIREITA.

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

Uma combinação bit a bit de valores Keys que representa a tecla ou as teclas a serem processadas.

Retornos

true se a tecla foi processada, caso contrário, false.

Exceções

A tecla SETA PARA A DIREITA faria com que o controle entrasse no modo de edição, mas a propriedade EditType da nova célula atual não indica uma classe derivada de Control e implementa IDataGridViewEditingControl.

Essa ação confirmaria um valor de célula ou entraria no modo de edição, mas um erro na fonte de dados impede a ação e, além disso, não há nenhum manipulador para o evento DataError ou o manipulador definiu a propriedade ThrowException como true.

Exemplos

O exemplo de código a seguir demonstra como alterar o comportamento da chave ENTER em uma DataGridView subclasse substituindo os ProcessDataGridViewKey métodos e ProcessDialogKey . No exemplo, a tecla ENTER tem o mesmo comportamento que a tecla SETA PARA A DIREITA, facilitando a edição de várias células por um usuário em uma única linha de dados.

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

Aplica-se a

Confira também