Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to detect only row change in grid.
Message
 
À
07/07/2000 08:05:00
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00389383
Message ID:
00390937
Vues:
9
>In my invoice detail grid whenever i change to row I want to change the balance qty for items. I tried using beforerowchange & afterrowchange events but they are activated even when fields from same row are changed.
>
>How can i detect only row change.
>
>Rajesh

Rajesh,

Add the following to your _base grid class:

******************
New Property - lDestroying
lDestroying = .f.

This property is required to prevent code from running when destoying. If the cursor is in the Grid and the form containing the grid is released the BeforeRowColChange will fire. I issue a SetAll('lDestorying',.t.) from my container and form _base class to handle this from happening.

******************
New Property - nLastRecordBottom
nLastRecordBottom = 0

******************
New Property - nLastRecordTop
nLastRecordTop = 0

******************
New Property - lChangingRecord with an access method.
lChangingRecord = .F.

Access method code:

PROCEDURE lchangingrecord_access
*To do: Modify this routine for the Access method
LOCAL lnRecordTop,lnRecordBottom,lnMouseRowPos,lnMouseColPos
WITH THIS
IF MDOWN() && OR nColIndex = 1 OR nColIndex = 2
lnRecordTop = .TOP+.HEADERHEIGHT + 2 + (.RELATIVEROW - 1) * .ROWHEIGHT + INT(.GRIDLINEWIDTH/2)
lnRecordBottom = .TOP+.HEADERHEIGHT + 1 + .RELATIVEROW * .ROWHEIGHT - INT(.GRIDLINEWIDTH/2)
lnMouseRowPos = MROW(WONTOP(),3)
lnMouseColPos = MCOL(WONTOP(),3)
IF NOT .RELATIVEROW = 0
THIS.nLastRecordTop = lnRecordTop
THIS.nLastRecordBottom = lnRecordBottom
ENDIF
IF BETWEEN(lnMouseRowPos,.TOP, .TOP+.HEIGHT) AND BETWEEN(lnMouseColPos,.LEFT,.LEFT+.WIDTH)
THIS.lChangingRecord = NOT BETWEEN(lnMouseRowPos,THIS.nLastRecordTop, THIS.nLastRecordBottom)
ENDIF
ELSE
THIS.lChangingRecord = INLIST(LASTKEY(),24,5,18,3,145,148) AND NOT THIS.lGridControlled
ENDIF
ENDWITH

******************
New Property - nCurrentRecord with an assign method

nCurrentRecord = 0

Assign method code:
PROCEDURE ncurrentrecord_assign
LPARAMETERS vNewVal
*To do: Modify this routine for the Assign method
IF THIS.ncurrentrecord # m.vNewVal
THIS.RecordChanged()
ENDIF
THIS.ncurrentrecord = m.vNewVal
ENDPROC

******************
New Method - RecordChanged: Should have no code in your _base class. Add code to subclasses to run when record changes.

******************
New Method - AllowRecordChange: Should have no code in your _base class. Add code to subclasses to evaluate if record change is allowed. This method must return TRUE or FALSE.

******************
Add the following code to existing methods:
PROCEDURE BeforeRowColChange
LPARAMETERS nColIndex
IF NOT THIS.lDestroying AND THIS.lChangingRecord
IF NOT THIS.AllowRecordChange()
NODEFAULT
ENDIF
ENDIF
ENDPROC


PROCEDURE When
LOCAL nWhere,nRelRow,nRelCol,nView
IF NOT THIS.lDestroying AND THIS.lChangingRecord IF NOT THIS.AllowRecordChange()
RETURN .F.
ENDIF
ENDIF
ENDPROC


PROCEDURE AfterRowColChange
LPARAMETERS nColIndex
THIS.nCurrentRecord = RECNO()
ENDPROC

Any code you want to run only when the row (record) has changed place in the RecordChanged method. To prevent the cursor from leaving a row (record) RETURN FALSE from the AllowRecordChange.

Bill
Heavy Metal Pedal - click with care
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform