IDataGridViewEditingControl.EditingControlWantsInputKey(Keys, Boolean) 方法

定义

确定指定的键是应由编辑控件处理的常规输入键,还是应由 DataGridView 处理的特殊键。Determines whether the specified key is a regular input key that the editing control should process or a special key that the DataGridView should process.

public:
 bool EditingControlWantsInputKey(System::Windows::Forms::Keys keyData, bool dataGridViewWantsInputKey);
public bool EditingControlWantsInputKey (System.Windows.Forms.Keys keyData, bool dataGridViewWantsInputKey);
abstract member EditingControlWantsInputKey : System.Windows.Forms.Keys * bool -> bool
Public Function EditingControlWantsInputKey (keyData As Keys, dataGridViewWantsInputKey As Boolean) As Boolean

参数

keyData
Keys

一个 Keys,表示按下的键。A Keys that represents the key that was pressed.

dataGridViewWantsInputKey
Boolean

DataGridView 要处理 keyData 中的 Keys 时,则为 true;否则为 falsetrue when the DataGridView wants to process the Keys in keyData; otherwise, false.

返回

如果指定的键是应由编辑控件处理的常规输入键,则为 true;否则为 falsetrue if the specified key is a regular input key that should be handled by the editing control; otherwise, false.

示例

下面的代码示例提供了此成员的实现。The following code example provides an implementation of this member. 此示例摘自了如何:Windows 窗体 DataGridView 单元中的主机控件。This example is part of a larger example available in How to: Host Controls in Windows Forms DataGridView Cells.

// Implements the IDataGridViewEditingControl.EditingControlWantsInputKey 
// method.
public bool EditingControlWantsInputKey(
    Keys key, bool dataGridViewWantsInputKey)
{
    // Let the DateTimePicker handle the keys listed.
    switch (key & Keys.KeyCode)
    {
        case Keys.Left:
        case Keys.Up:
        case Keys.Down:
        case Keys.Right:
        case Keys.Home:
        case Keys.End:
        case Keys.PageDown:
        case Keys.PageUp:
            return true;
        default:
            return !dataGridViewWantsInputKey;
    }
}
Public Function EditingControlWantsInputKey(ByVal key As Keys, _
    ByVal dataGridViewWantsInputKey As Boolean) As Boolean _
    Implements IDataGridViewEditingControl.EditingControlWantsInputKey

    ' Let the DateTimePicker handle the keys listed.
    Select Case key And Keys.KeyCode
        Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, _
            Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp

            Return True

        Case Else
            Return Not dataGridViewWantsInputKey
    End Select

End Function

注解

编辑控件实现此方法以确定控件应处理的输入键, 以及应由DataGridView处理的输入键。An editing control implements this method to determine which input keys should be processed by the control, and which input keys should be processed by the DataGridView.

EditingControlWantsInputKey方法由DataGridView调用。The EditingControlWantsInputKey method is called by the DataGridView. 当可以DataGridView true 处理keyData时, 将传入。 dataGridViewWantsInputKeyThe DataGridView will pass in true for dataGridViewWantsInputKey when it can process the keyData. 如果编辑控件DataGridView可以让keyData句柄, EditingControlWantsInputKey则在为truefalse dataGridViewWantsInputKey应返回。If the editing control can let the DataGridView handle the keyData, EditingControlWantsInputKey should return false when dataGridViewWantsInputKey is true. EditingControlWantsInputKey其他实现可能会dataGridViewWantsInputKey忽略的keyDatatrue , 并在编辑控件中处理。Other implementations of EditingControlWantsInputKey may ignore a dataGridViewWantsInputKey value of true and handle the keyData in the editing control.

适用于

另请参阅