Lazarus

Programming => General => Topic started by: Raj Gupta on June 22, 2019, 09:01:16 am

Title: StringGrid Sum of Column.
Post by: Raj Gupta on June 22, 2019, 09:01:16 am
StringGrid Editing is on. On Enter Key Press a new Row is added automatically.

Total is is Column Title Head.

I want to get sum of [Total] Column in LabelTotal.Caption.

How to achieve this.
Title: Re: StringGrid Sum of Column.
Post by: wp on June 22, 2019, 11:46:25 am
Use the OnEditingDone event of the grid, interate though the cells in the column that you want to sum, calculate the sum, convert it to a string and assign that to the LabelTotal.Caption.
Title: Re: StringGrid Sum of Column.
Post by: Raj Gupta on June 22, 2019, 03:29:47 pm
Use the OnEditingDone event of the grid, interate though the cells in the column that you want to sum, calculate the sum, convert it to a string and assign that to the LabelTotal.Caption.

Plz give me a sample code of your explanation.
Thanks.
Title: Re: StringGrid Sum of Column.
Post by: wp on June 22, 2019, 04:59:23 pm
I hope this is not some homework assignment...

See the attachment. It calculates the row sum and well as the grand total of the "Totals" column. It also prevents that the user can enter anything into the "Totals" column himself.

[EDIT]
Replaced the attachment against one that works correctly in a non-trunk version of Lazarus. Sorry...
TinyPortal © 2005-2018