|sValue (ByRef)||A byref value which this event should fill with the calculated value|
Procedure OnSetCalculatedValue String ByRef sValue
Data aware grids usually fetch their data automatically and dynamically as needed. Each time a row needs to be filled, InitialValue is called for each column. InitialValue is used to move the data from the table buffer into the grid column. It does this by using the piBindingTable and piBindingColumn properties. If there is no binding table (piBindingTable is 0), the column is considered to be a calculated column and the initial data is filled by sending the OnSetCalculatedValue event. This event passes the current value (usually "") as sValue. This parameter is a by reference value and you set a calculated value by changing sValue. This initial value is then placed in the datasource and displayed in the grid.
Normally, a calculated column should be set to be non-focusable (pbFocusable is False).
Object oDiscount is a cDbCJGridColumn Send CreateCurrencyMask 6 2 Set pbFocusable to False Set piWidth to 75 Set psCaption to "Discount" Procedure OnSetCalculatedValue String ByRef sValue Move (Invt.Unit_Price * .85) to sValue End_Procedure End_Object
When this event is called, the proper data will be loaded in your table buffers and you can use this data as part of your calculation. However, you cannot use data in your DataDictionary Object (DDO). When data is loaded into your datasource, the DataDictionary's current record is not yet set (and it may never be set). Therefore, you must base your calculations on your external data (i.e., table buffers) and not on your DataDictionary (i.e., don't use Field_Current_Value).
This event should be used for setting an initial calculated value. The cDbCJGridDataSource determines when this event is called. It is called when a new row is added and anytime the cDbCJGrid receives the Refresh message. This means the calculation is called every time you find a record, which can be part of changing rows, finding a new row, or changing a parent record. This event is not called each time you change a column or change a column's value. This matches the behavior of the Entry_Item command when used with expressions.
You cannot use the Entry_Item command with an expression in cDbCJGridColumn objects. Instead, you should use this event. The following code is not supported:
Object oDiscount is a cDbCJGridColumn Send CreateCurrencyMask 6 2 Set pbFocusable to False Set piWidth to 75 Set psCaption to "Discount" // this is NOT allowed. Use OnSetCalculatedValue Entry_Item (Invt.Unit_Price * .85) End_Object
Using OnSetCalculatedValue provides a more flexible mechanism for setting calculated columns. It can do everything Entry_Item does and has the advantage that you can add whatever kind of conditional processing code you wish.
Object oDiscount is a cDbCJGridColumn Send CreateCurrencyMask 6 2 Set pbFocusable to False Set piWidth to 75 Set psCaption to "Discount" Procedure OnSetCalculatedValue String ByRef sValue Boolean bGoodCustomer Number nRate Get pbGoodCustomer to bGoodCustomer If (bGoodCustomer) Begin Get pnGoodRate to nRate Move (Invt.Unit_Price * nRate) to sValue End Else Begin Move (Invt.Unit_Price * 1.15) to sValue End End_Procedure End_Object
This event is only supported with data-aware girds. A simple cCJGrid does not need a calculated column event. If you need an initial calculated column value, just create it when you are filling your datasource.See Also
OnEndEdit | UpdateCurrentValue