Recent

Author Topic: StringGrid Sum of Column.  (Read 761 times)

Raj Gupta

  • New Member
  • *
  • Posts: 34
StringGrid Sum of Column.
« 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.

wp

  • Hero Member
  • *****
  • Posts: 7552
Re: StringGrid Sum of Column.
« Reply #1 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.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Raj Gupta

  • New Member
  • *
  • Posts: 34
Re: StringGrid Sum of Column.
« Reply #2 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.

wp

  • Hero Member
  • *****
  • Posts: 7552
Re: StringGrid Sum of Column.
« Reply #3 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...
« Last Edit: June 22, 2019, 06:26:34 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018