KeyPressEdit Event

Fired when the user presses a key in cell-editing mode.

Syntax

Private Sub VSFlexGrid_KeyPressEdit( ByVal Row As Long,  ByVal Col As Long, KeyAscii As Integer)

Remarks

This event is similar to the standard KeyPress event, except it is fired while the grid is in edit mode.

The editor has three modes: text, drop-down combo, or drop-down list. The mode used is determined by the ComboList and ColComboList properties.

While editing with the text editor or with a drop-down combo, you may set or retrieve the contents of the editor using the EditText property. You may manipulate the contents of the editor using the EditSelStart, EditSelLength, and EditSelText properties.

While editing with drop-down lists or drop-down combos, you may set or retrieve the contents of the editor using the ComboItem, ComboIndex, ComboCount, and ComboData properties.

The main use for this event is to filter keys as they are typed while the control is in cell-editing mode. For example, the code below shows how you can convert input to upper-case or restrict data entry to numeric values only.

Sub fg_KeyPressEdit(Row As Long, Col As Long, KeyAscii As Integer)

    Select Case Col

    ' column 1 entries are upper case

    ' so use VB's UCase function to convert the character

     Case 1: KeyAscii = Asc(UCase$(Chr$(KeyAscii)))

     ' column 2 entries are numeric

     ' so set KeyAscii to 0 if it is not a digit

     Case 2: If KeyAscii < vbKey0 Or KeyAscii > vbKey9 Then KeyAscii = 0

 

    End Select

End Sub

Note that you could also restrict the input of non-digits using the EditMask or ColEditMask properties.

See Also

VSFlexGrid Control