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ávese.

Návraty

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

Výjimky

Stisknutí klávesy způsobí, že ovládací prvek přejde do režimu úprav, ale EditType vlastnost aktuální buňky neoznačuje třídu, která je odvozena z Control a 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ď pro událost neexistuje žádná obslužná rutina 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ď pro událost neexistuje žádná obslužná rutina 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 podtřídě DataGridView přepsáním ProcessDataGridViewKey metod a ProcessDialogKey . V tomto 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íče odpovídající stisknuté klávese (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 vrátit true ovládací prvek, který označuje, že klíč zpracoval. Pro klíče, které nejsou zpracovány ovládacím prvku, vrátí výsledek základní verze této metody.

Platí pro

Viz také