||Re: how to calculate 2 records of the same column of a grid?
||Wed, 13 Jan 2021 10:57:02 +1000
1. ensure that there is an active index for the rowset on the unique row
identifier. Since it is energy consumption, I assume you have a
timestamp or date to identify your records.
2. set the multiselect property of the grid to true
3. define an onLeftMouseUp event for your grid and put the following
code in it (replace the field name as needed):
if a.size>1 // to avoid triggering the code for any click on the grid
nSum=0 // initialise the counter to allow '+=' accumulation
//deqactivate grid update while the code scrolls through the records
this.parent.rowset.notifyControls := false
for i=1 to a.size
//reactivate grid update
this.parent.rowset.notifyControls := true
4. click on the first row that you want to include in the selection,
hold the shift key and click on the last row you want to include in the
selection (you can click on the grid's scroll bars as it won't change
the selection of the first row and won't trigger the code either)
5. the msgbox will show the accumulated values for the selected range
upon releasing the left button of the mouse and provided you selected
more than one record.
This assumes the selection is always contiguous. For random selections,
you can still use this code but you need to attach it to a pushbutton
instead of to the onLeftMouseUp so that you won't need the if a.size>1
check to avoid getting the value updated with every ctrl+click on the
grid to select random records.
Attaching the code to a pushbutton may also help prevent accidental
triggering of the code while scrolling and selecting an unwanted record.
Hope this helps,
On 13/01/2021 6:00, Dirk wrote:
> i am trying to calculate 2 records of the same column as excel, make a
> sum in a calculated fields, by clicking on the grid cell
> means want to know the consume of solar electricty in a certain period
> i can of course use 2 colums , 2 fields : 1 begin and 1 end
> but begin of column 1 day x, should be end of column end day - 15
> day is date field i put the info into
> so, to avoid a column i trying to find out a way as excel
> thanks for a helping hand
> best regards