Page 1 of 1
Sum column of a data grid
Posted: Sat Nov 03, 2018 5:40 pm
by cbarbal
Hi,
I just did the lesson "How Do I Get Aggregate Values for Columns?", Which calculates the total by a button. I would like it to be done automatically when the data grid is filled, without using the button. It's possible?
Thanks in advance,
Carles
Re: Sum column of a data grid
Posted: Sat Nov 03, 2018 6:10 pm
by bogs
I am sure it is possible, although I am no expert with the datagrid. Some things you *might* try -
Take your code out of the button and put it in another message path, like the dg group handler 'closeControl', which I believe triggers when you leave the grid.
Depending on how you navigate the grid, you can make your own handler, and trigger the code currently in the button by moving it to your handler.
Lets say you use the 'tab' key to move through the grid. You want your column to auto sum up on every tab key, so you might put in the dg script -
Down in the card or stack script, your handler would get the button script, which would be activated anytime the tab key is pressed from the dg group.
*Edit for clarity -
You could put the button script into the tabKey handler directly, the reason I suggested writing out the separate handler is because you could be navigating the grid in any number of ways, instead of repeatedly pasting the script into each one, you write the handler once and refer to it in every way you can / will allow the navigation.
I'm sure someone with a lot more familiarity with the dg will chime in shortly.
Re: Sum column of a data grid
Posted: Sat Nov 03, 2018 6:12 pm
by Klaus
Hola Carles,
sure, put the handler under a new name (maybe "your_calculation" instead of "mouseup") into the card or even stack script and execute it right after you have filled your datagrid.
Code: Select all
...
set the dgtext of grp "your datagrid here" to whatever_variable
## Do your calculation here
your_calculation
...
Best
Klaus
Re: Sum column of a data grid
Posted: Sat Nov 03, 2018 6:45 pm
by cbarbal
Thank you very much, bogs and Klaus for the answers.
In the script that loads the data grid have added the text of the script of the button and it does it automatically.
Regards,
Carles
Re: Sum column of a data grid
Posted: Sat Nov 03, 2018 7:09 pm
by bogs
Yes, that would work too, but don't you need the totals updated as the program runs along? In any case, glad you figured it out

Re: Sum column of a data grid
Posted: Sat Nov 03, 2018 7:57 pm
by cbarbal
Hi bogs,
Not at the beginning. The data grid is filled with the revenues, expenses and the annual balance that are in other SQL tables. Each time I select a row of the "mother" data grid, I fill in the data in another data grid that executes the script that recalculates it.
Regards,
Carles
Re: Sum column of a data grid
Posted: Sat Nov 03, 2018 9:16 pm
by bogs
Ahh, I get it
