DataGridView.ProcessRightKey(Keys) Método

Definição

Processa a tecla 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 Keys valores que representa a chave ou chaves a processar.

Devoluções

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

Exceções

A tecla SETA DIREITA faria o controlo entrar em modo de edição, mas a EditType propriedade da nova célula atual não indica uma classe que derive de Control e implemente IDataGridViewEditingControl.

Esta ação comprometeria um valor de célula ou entraria em modo de edição, mas um erro na fonte de dados impede a ação e ou não existe um handler para o DataError evento ou o handler definiu a ThrowException propriedade para true.

Exemplos

O seguinte exemplo de código demonstra como alterar o comportamento da tecla ENTER numa DataGridView subclasse sobrescrevendo os ProcessDataGridViewKey métodos e.ProcessDialogKey No exemplo, a tecla ENTER tem o mesmo comportamento da tecla DIREITA, facilitando ao utilizador a edição de múltiplas células numa ú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

Ver também