ValidateEdit Event

Fired before the control exits cell edit mode.

Syntax

Private Sub VSFlexGrid_ValidateEdit( ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)

Remarks

This event is fired before any changes made by the user are committed to the cell.

You may trap this event to read the contents of the cell editor with the EditText property and to make sure the entry is valid for the given cell (Row, Col). If the entry fails validation, set the Cancel parameter to True. The changes will be discarded and the control will remain in edit mode.

If you want to validate keys as they are typed into the editor, use the KeyPressEdit or the ChangeEdit events. For more details on in-cell editing, see the Editable and ComboList properties.

For example, the code below shows a typical handler for the ValidateEdit event. In this case, column 1 only accepts strings, and column 2 only accepts numbers greater than zero:

Sub fg_ValidateEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)

        Dim c$

        Select Case Col ' different validation rules for each column

            Case 1      ' column 1 only accepts strings

                c = Left$(fg.EditText, 1)

                If UCaseS(c) < "A" And UCase$(c) > "Z" Then Beep: Cancel = True

            Case 2      ' column 2 only accepts numbers > 0

                If Val(fg.EditText) <= 0 Then Beep: Cancel = True

        End Select

End Sub

See Also

VSFlexGrid Control