DataGridView.ProcessRightKey(Keys) Metodo

Definizione

Elabora il tasto FRECCIA DESTRA.

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

Parametri

keyData
Keys

Combinazione bit per bit di Keys valori che rappresenta la chiave o le chiavi da elaborare.

Valori restituiti

true se la chiave è stata elaborata; in caso contrario, false.

Eccezioni

Il tasto FRECCIA DESTRA fa sì che il controllo entri in modalità di modifica, ma la EditType proprietà della nuova cella corrente non indica una classe che deriva da Control e implementa IDataGridViewEditingControl.

Questa azione eseguirà il commit di un valore di cella o si attiva la modalità di modifica, ma un errore nell'origine dati impedisce l'azione e non esiste alcun gestore per l'evento DataError o il gestore ha impostato la ThrowException proprietà su true.

Esempio

Nell'esempio di codice seguente viene illustrato come modificare il comportamento della chiave ENTER in una DataGridView sottoclasse eseguendo l'override dei ProcessDataGridViewKey metodi e ProcessDialogKey . Nell'esempio, il tasto INVIO ha lo stesso comportamento del tasto FRECCIA DESTRA, rendendo più semplice per un utente modificare più celle in una singola riga di dati.

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

Si applica a

Vedi anche