DataGridView.ProcessDataGridViewKey(KeyEventArgs) Metoda

Definice

Zpracovává klíče používané k navigaci v objektu DataGridView.

protected:
 virtual bool ProcessDataGridViewKey(System::Windows::Forms::KeyEventArgs ^ e);
protected virtual bool ProcessDataGridViewKey(System.Windows.Forms.KeyEventArgs e);
abstract member ProcessDataGridViewKey : System.Windows.Forms.KeyEventArgs -> bool
override this.ProcessDataGridViewKey : System.Windows.Forms.KeyEventArgs -> bool
Protected Overridable Function ProcessDataGridViewKey (e As KeyEventArgs) As Boolean

Parametry

e
KeyEventArgs

Obsahuje informace o stisknuté klávesě.

Návraty

truepokud byl klíč zpracován; v opačném případě . false

Výjimky

Stisknutá klávesa způsobí, že ovládací prvek přejde do režimu úprav, ale EditType vlastnost aktuální buňky neznačí třídu, která je odvozena a Control implementuje IDataGridViewEditingControl.

Tato akce potvrdí hodnotu buňky nebo přejde do režimu úprav, ale chyba ve zdroji dat zabrání akci a buď neexistuje žádná obslužná rutina události DataError , nebo obslužná rutina nastavila ThrowException vlastnost na true.

nebo

Klíč DELETE by odstranil jeden nebo více řádků, ale chyba ve zdroji dat brání odstranění a buď neexistuje žádná obslužná rutina události DataError , nebo obslužná rutina nastavila ThrowException vlastnost na true.

Příklady

Následující příklad kódu ukazuje, jak změnit chování klávesy ENTER v DataGridView podtřídě přepsáním ProcessDataGridViewKey a ProcessDialogKey metodami. V příkladu má klávesa ENTER stejné chování jako klávesa ŠIPKA VPRAVO, což uživateli usnadňuje úpravu více buněk v jednom řádku dat.

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

Poznámky

Tato metoda volá metodu zpracování kláves odpovídající stisknutí klávesy (například metodu ProcessF2Key při stisknutí klávesy F2) a vrátí návratovou hodnotu této metody.

Poznámky pro dědice

Při přepsání této metody by se měl ovládací prvek vrátit true a indikovat, že klíč zpracoval. U klíčů, které ovládací prvek nezpracovávají, vrátí výsledek základní verze této metody.

Platí pro

Viz také