GrapeCity MultiRow Windows Forms Documentation
OnKeyDown Method (Cell)
Example 


A CellKeyEventArgs that contains the event data.
Raises the events related to pressing the character keys.
Syntax
Protected Overridable Sub OnKeyDown( _
   ByVal e As CellKeyEventArgs _
) 
Dim instance As Cell
Dim e As CellKeyEventArgs
 
instance.OnKeyDown(e)
protected virtual void OnKeyDown( 
   CellKeyEventArgs e
)

Parameters

e
A CellKeyEventArgs that contains the event data.
Remarks

Raising an event invokes the event handler through a delegate.

The OnKeyDown method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Notes to Inheritors: When overriding OnKeyDown in a derived class, be sure to call the base class's OnKeyDown method so that registered delegates receive the event.

Example
The following code example shows how to use this method to customize a cell's keyboard behavior. This code example is part of a larger example provided for the IEditingCell interface.
protected override void OnKeyDown(CellKeyEventArgs e)
        {
            // Handle keyboard message in edit mode.
            if (this.GcMultiRow.CurrentCell.RowIndex == e.RowIndex &&
                this.GcMultiRow.CurrentCell.CellIndex == e.CellIndex &&
                this.GcMultiRow.IsCurrentCellInEditMode)
            {

                if (e.KeyData == Keys.Add || e.KeyData == Keys.Right)
                {
                    this.EditingCellFormattedValue = _editingValue + 1;
                }
                else if (e.KeyData == Keys.Subtract || e.KeyData == Keys.Left)
                {
                    this.EditingCellFormattedValue = _editingValue - 1;
                }
                base.OnKeyDown(e);
            }
        }
Protected Overloads Overrides Sub OnKeyDown(ByVal e As CellKeyEventArgs)
        ' Handle keyboard message in edit mode.
        If Me.GcMultiRow.CurrentCell.RowIndex = e.RowIndex AndAlso Me.GcMultiRow.CurrentCell.CellIndex = 
e.CellIndex AndAlso Me.GcMultiRow.IsCurrentCellInEditMode Then

            If e.KeyData = Keys.Add OrElse e.KeyData = Keys.Right Then
                Me.EditingCellFormattedValue = _editingValue + 1
            ElseIf e.KeyData = Keys.Subtract OrElse e.KeyData = Keys.Left Then
                Me.EditingCellFormattedValue = _editingValue - 1
            End If
            MyBase.OnKeyDown(e)
        End If
    End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

Cell Class
Cell Members
OnKeyPress Method
OnKeyUp Method

 

 


Copyright © GrapeCity, inc. All rights reserved.