DataGridView.ProcessRightKey(Keys) Metoda

Definicja

Przetwarza klawisz STRZAŁKI W PRAWO.

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

Parametry

keyData
Keys

Bitowa kombinacja wartości reprezentujących Keys klucz lub klucze do przetworzenia.

Zwraca

true jeśli klucz został przetworzony; w przeciwnym razie , false.

Wyjątki

Klawisz STRZAŁKA W PRAWO spowoduje wprowadzenie kontrolki w trybie edycji, ale EditType właściwość nowej bieżącej komórki nie wskazuje klasy pochodzącej z Control i implementuje IDataGridViewEditingControl.

Ta akcja spowoduje zatwierdzenie wartości komórki lub wprowadzenie trybu edycji, ale błąd w źródle danych uniemożliwia działanie i nie ma procedury obsługi dla DataError zdarzenia lub program obsługi ustawił ThrowException właściwość na true.

Przykłady

W poniższym przykładzie kodu pokazano, jak zmienić zachowanie klucza ENTER w podklasie DataGridView przez zastąpienie ProcessDataGridViewKey metod i ProcessDialogKey . W tym przykładzie klucz ENTER ma takie samo zachowanie jak klawisz STRZAŁKA W PRAWO, co ułatwia użytkownikowi edytowanie wielu komórek w jednym wierszu danych.

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

Dotyczy

Zobacz też