DataGridView.ProcessRightKey(Keys) Méthode

Définition

Traite la touche FLÈCHE DROITE.

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

Paramètres

keyData
Keys

Combinaison de valeurs au niveau du Keys bit qui représente la clé ou les clés à traiter.

Retours

true si la clé a été traitée ; sinon, false.

Exceptions

La touche FLÈCHE DROITE entraîne l’entrée du contrôle en mode d’édition, mais la EditType propriété de la nouvelle cellule active n’indique pas de classe qui dérive Control et implémente IDataGridViewEditingControl.

Cette action validerait une valeur de cellule ou entrerait en mode d’édition, mais une erreur dans la source de données empêche l’action et il n’existe aucun gestionnaire pour l’événement DataError ou le gestionnaire a défini la ThrowException propriété truesur .

Exemples

L’exemple de code suivant montre comment modifier le comportement de la clé ENTER dans une DataGridView sous-classe en remplaçant les méthodes et ProcessDataGridViewKey les ProcessDialogKey méthodes. Dans l’exemple, la touche ENTRÉE a le même comportement que la touche FLÈCHE DROITE, ce qui facilite la modification de plusieurs cellules par un utilisateur dans une seule ligne de données.

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

S’applique à

Voir aussi