DataGridView.ProcessDataGridViewKey(KeyEventArgs) Yöntem

Tanım

içinde DataGridViewgezinmek için kullanılan anahtarları işler.

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

Parametreler

e
KeyEventArgs

Basılan anahtar hakkında bilgi içerir.

Döndürülenler

true anahtar işlendiyse; aksi takdirde , false.

Özel durumlar

Basılan tuş denetimin düzenleme moduna girmesine neden olur, ancak EditType geçerli hücrenin özelliği öğesinden Control türetilen ve uygulayan IDataGridViewEditingControlbir sınıfı göstermez.

Bu eylem bir hücre değeri işler veya düzenleme moduna girer, ancak veri kaynağındaki bir hata eylemi engeller ve olay için DataError işleyici yoktur veya işleyici özelliği olarak ThrowExceptionayarlamıştırtrue.

-veya-

DELETE anahtarı bir veya daha fazla satırı siler, ancak veri kaynağındaki bir hata silme işlemini engeller ve olay için DataError işleyici yoktur veya işleyici özelliğini olarak ThrowExceptionayarlamıştırtrue.

Örnekler

Aşağıdaki kod örneği, ve DataGridView yöntemlerini geçersiz kılarak bir ProcessDataGridViewKey alt sınıftaKI ENTER anahtarının davranışını değiştirme işlemini ProcessDialogKey gösterir. Örnekte, ENTER tuşu SAĞ OK tuşuyla aynı davranışa sahiptir ve bu da kullanıcının tek bir veri satırındaki birden çok hücreyi düzenlemesini kolaylaştırır.

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

Açıklamalar

Bu yöntem, basılan tuşa (örneğin, F2 tuşuna basıldığında yöntemi ProcessF2Key ) uygun anahtar işleme yöntemini çağırır ve bu yöntemin dönüş değerini döndürür.

Devralanlara Notlar

Bu yöntem geçersiz kılınırken, anahtarı işlediğini belirtmek için bir denetim döndürülmelidir true . Denetim tarafından işlenmemiş anahtarlar için bu yöntemin temel sürümünün sonucunu döndürür.

Şunlara uygulanır

Ayrıca bkz.