Hi Marcia,
Two questions:
1)Will it work for navigation buttons too?
2) Can I use form's properties instead of grid's properties?
Otherwise I have to subclass our grid class for this particular application...
>Hi Nadya.
>
>>> I have a form with a grid and textboxes. I can navigate using navigation buttons or by moving directly in a grid. If user left some textboxes unfilled, I want to stay on this record and don't allow to move to another record. I don't want to touch navigation button class, if it could be avoided. <<
>
>Add 2 custom properties to your grid class: nRec2Validate and lValidatingRow. Add a template method to the grid class called ValidateCurrentRow: code to go in the instance.
>
>This code in BeforeRowColChange:
>
>
>WITH This
> IF .lValidatingRow
> NODEFAULT
> ELSE
> .nRec2Validate = RECNO(.RecordSource)
> ENDIF
>ENDWITH
>
>
>This code in AfterRowColChange:
>
>
>LOCAL lnRec2GoTo
>WITH This
> *** If there is no record to validate, exit stage left
> IF .nRec2Validate = 0
> RETURN
> ENDIF
>
> *** Save the current record number in case we have changed rows
> lnRec2GoTo = RECNO( .RecordSource )
>
> *** Check to see if the row has changed
> IF .nRec2Validate # lnRec2GoTo
> *** We are validating the row we are attempting to leave...set the flag
> .lValidatingRow = .T.
> *** Return to the record we just left
> GOTO .nRec2Validate IN ( .RecordSource )
> *** If it checks out, let the user move to the new row
> IF .ValidateCurrentRow()
> GOTO lnRec2GoTo IN ( .RecordSource )
> .RefreshControls()
> ENDIF
> *** Finished with validation...reset flag
> .lValidatingRow = .F.
> ENDIF
>ENDWITH
>
>
>RefreshControls is a template method that my base class grid has. I use it to refresh dependent controls on the form.
>
>HTH
If it's not broken, fix it until it is.
My Blog