Page 1 of 1

Getting the total of the values in a column in a datagrid.

Posted: Mon Jun 12, 2023 10:31 am
by CAsba
Hi,
I have a datagrid table to show the contents of an invoice. Each row - item, price, quantity, total, comprises the sales detail of a product. There may be several different products on the invoice, so several rows. My problem is, I want to add the total of the totals in the last column to present a grand total.
It occurs to me that I could do the addition, row by row, outside the dg, adding each total to an outside field then entering the field back into the DG, but one of you guys might know a more elegant way to do it, a single (simple) line of code perhaps ? Hope I've explained it properly. Looking forward to hearing from you..

Re: Getting the total of the values in a column in a datagrid.

Posted: Mon Jun 12, 2023 12:49 pm
by Klaus
No tricks available here, you will need to make a repeat loop of some sort.

Re: Getting the total of the values in a column in a datagrid.

Posted: Mon Jun 12, 2023 3:33 pm
by SparkOut

Re: Getting the total of the values in a column in a datagrid.

Posted: Tue Jun 13, 2023 4:35 pm
by dunbarx
CAsba.
I could do the addition, row by row, outside the dg,
Just what I would do. Use the "dgText" property to get the data out.

Craig

Re: Getting the total of the values in a column in a datagrid.

Posted: Wed Jun 14, 2023 6:01 pm
by stam
Just a comment - using dgText means you need to extract item x of each line. But that may causes issues down the line if you add/remove/reorder columns as that “x” may shift to a different number.

Another approach is to do the same but with the data in array form (ie dgData instead of dgText). That way you’ll always refer to the key/column by name and order is not important.
Just a thought…

S.

Re: Getting the total of the values in a column in a datagrid.

Posted: Fri Jun 16, 2023 12:02 pm
by CAsba
Thanks for that.