Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Total of a column from grid
Message
From
08/11/2000 13:15:20
 
 
To
07/11/2000 06:50:02
Sammy Derban
Ghana Telecom
Accra, Ghana
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Miscellaneous
Thread ID:
00438706
Message ID:
00439301
Views:
17
Sammy:

Below is an example that I once gave to someone else. The example uses one table (EprMstr) and one view (lvEprDtl) in a parent-child relationship. The grid is used to display the child records.


1. Use a ReadOnly textbox (txtTotal in the example below).
2. Calculate the total in txtTotal::Refresh()
3. If the total is supposed to balance to something known, put code
in txtTotal::ProgrammaticChange().
4. In the column that you want summed, put code in the LostFocus
event of the grid column control (called txtGrossPay in the
example below) to update the total.
5. Add code in the grid's Deleted event to update the total if
DeleteMark is True.

Note:
Updating the total is not as trivial as it sounds because detail lines
can be deleted. Note that clicking on the Delete Mark does NOT trigger
the LostFocus event of the grid column's control.

*=========================
* txtTotal::Refresh event
*=========================

LOCAL lcAlias && The currently selected table alias.
LOCAL llLockScreen && The form's LockScreen status.
LOCAL lnRecNo && The EprDtl currently selected record number.
LOCAL lnTotal && The sum of the gross pay
LOCAL lnTracingId && The main table primary key evaluation.

* ----------------------------------
* -- Calculate the total gross pay.
* ----------------------------------
lcAlias = ALIAS()
llLockScreen = THISFORM.LockScreen
lnRecNo = IIF(EOF("lvEprDtl"), 0, RECNO("lvEprDtl"))
lnTracingId = EprMstr.TracingId

THISFORM.LockScreen = .T.
SELECT lvEprDtl
CALCULATE SUM(GrossPay) ;
FOR lvEprDtl.TracingId = m.lnTracingId AND ;
NOT DELETED("lvEprDtl") ;
TO m.lnTotal

IF m.lnRecNo <> 0
GO (m.lnRecNo) IN lvEprDtl
ELSE
GO TOP IN lvEprDtl
ENDIF

=RestoreAlias(m.lcAlias)
THISFORM.LockScreen = m.llLockScreen
THIS.Value = m.lnTotal

*====================================
* txtTotal::ProgrammaticChange event
*====================================
* -- Give visual clues if totals are not matching.

IF THIS.Value = THISFORM.ComparisonValue
THIS.ResetToDefault("DisabledBackColor")
THIS.ResetToDefault("ForeColor")
ELSE
IF goApp.BackColorDiscrepancy <> -1
THIS.DisabledBackColor = goApp.BackColorDiscrepancy
ELSE
THIS.ResetToDefault("DisabledBackColor")
ENDIF

IF goApp.ForeColorDiscrepancy <> -1
THIS.ForeColor = goApp.ForeColorDiscrepancy
ELSE
THIS.ResetToDefault("ForeColor")
ENDIF
ENDIF


*==============================
* txtGrossPay::LostFocus event
*==============================

THISFORM.txtTotal.Refresh()

*=============================
* grdDocuments::Deleted event
*=============================
*-- Update total
*--
*-- REMARKS:
*-- --------
*-- 1. This event is triggered for both DELETE and RECALL
*-- 2. The DELETED() value is the value BEFORE the delete or recall.
*-- (DELETED() is true if recalling a record)
*-- 3. If the Gross Pay textbox has focus and the user clicks on a delete
*-- mark, the LostFocus event of the textbox is NOT triggered. If the
*-- click is on the current record. the textbox keeps focus. If the
*-- click is on another record, the textbox value is reverted and the
*-- focus passes to the Gross Pay textbox associated with the
*-- record clicked on.

LPARAMETERS tnRecNo

LOCAL llRetVal && Value returned by this method.
LOCAL lnCurrRec

llRetVal = DODEFAULT(m.tnRecNo)
IF m.llRetVal
lnCurrRec = RECNO("lvEprDtl")
GO (m.tnRecNo) IN lvEprDtl

WITH THISFORM.txtTotal
IF DELETED("lvEprDtl")
.Value = .Value + lvEprDtl.GrossPay
ELSE
.Value = .Value - lvEprDtl.GrossPay
ENDIF
ENDWITH

IF m.lnCurrRec <> 0
GO (m.lnCurrRec) IN lvEprDtl
ENDIF
ENDIF


RETURN (m.llRetVal)
Previous
Reply
Map
View

Click here to load this message in the networking platform