Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Determine row change in Grid

Status
Not open for further replies.

nallen

IS-IT--Management
Oct 20, 2003
10
US
How do I determine if the user changed rows in a grid. I'm using VFP 5.0. I understand there's 'rowcolchange' in VFP 8 or 9, but how do I test for this in VFP 5.0. I'm trying to setup the grid's BeforeRowColChange event so it will not change Rows but will allow column changes when in an editmode (say, myeditmode = .t.).
 
You need to create a couple of properties (I would suggest doing so on your base class grid) and set them manually in the AfterRowColChange(). One property will hold the record number of the cursor (for row changes), the other will hold the column number (so you can also check for column changes).

The column number property can be set in the AfterRowColChange() method using the parameter passed into the method by VFP.

LPARAMETERS nColIndex

The record number is available via RECNO(). Now you can compare them in the BeforeRowColChange() event.




_RAS
VFP MVP
 
I must be missing something. I can create a property, call it 'Current_Row' and set it to Current_Row = RECNO() in the AfterRowColChange event of the grid. This gives me the recno() I'm on in the cursor.

However, to then see if I'm about to leave this row to enter a new row in the grid, what do I put in the BeforeRowColChange event of the grid? If I put:

IF Current_Row <> RECNO()
*Don't fire the event - don't leave the row
NODEFAULT
ENDIF

This isn't working because Recno() when in this event IS EQUAL to the Current_Row.

Help....
ThankS
 
Hello Nallen.

The only way that you can do what you want is to save the record you were on in BeforeRowColChange and then see if it matches the record you are in in AfterRowColChange as illustrated in the following code. Of course, a better solution would be to upgtade to VFP version 8. The grid has a RowColChange property that tells you whether the Row Changed, the column changed or both changed. Besides, Version 5 of VFP was buggy to begin with. Just curious - do you have a good reason for not upgrading?

Add 2 custom properties to your grid class:

lValidatingRow (logical)
nRec2Validate (integer)

This code in the grid's BeforeRowColChange:

Code:
WITH This
  IF .lValidatingRow
    NODEFAULT
  ELSE    
    .nRec2Validate = RECNO(.RecordSource)
  ENDIF
ENDWITH

This code goes in AfterRowColChange:

Code:
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 )
    ENDIF
    *** Finished with validation...reset flag
    .lValidatingRow = .F.
  ENDIF
ENDWITH

Marcia G. Akins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top