Board index » delphi » Show Column Sum in DBGrid?

Show Column Sum in DBGrid?

Sounds simple (and is, if you do it in MS Access): how can I show a
sum below a numeric column of a DBGrid?

Any tips greatly appreciated!

Bernd

 

Re:Show Column Sum in DBGrid?


Well, I think the normal way to show a sum for a DBgrid is make it a
separate control just below the grid (that's what I do on my forms). That
way, if you need to scroll the grid vertically, the total is always there
and it's easy to implement and is intuitive enough.

If you really want the total to be actually part of the DB grid and show up
at the bottom of the DBgrid list, then you have to do something either
kludgy or tricky. For example, you could try one of the following (warning:
I haven't tried this myself!):

* Temporarily add a totals record to the end of the table being displayed
in the grid after computing totals. This is kind of ugly since you'd have
to keep finding and updating that record each time the other records
changed. You'd also have to keep it at the end of the table. Very arduous.

* Capture the OnDrawGridColumn (or whatever the event is for drawing a grid
cell) and check for the last record. If it is the last record, see if the
record after it (blank) is visible on the screen. If it is, scribble totals
on it while you are drawing the last record.

Just some ideas...

Mark

B. Weikert <b.weik...@aon.at> wrote in article
<5mk95d$md...@garion.telecom.at>...

Quote
> Sounds simple (and is, if you do it in MS Access): how can I show a
> sum below a numeric column of a DBGrid?

> Any tips greatly appreciated!

> Bernd

Re:Show Column Sum in DBGrid?


Quote
"Mark Bratcher" <mbra...@ix.netcom.com> wrote:
>Well, I think the normal way to show a sum for a DBgrid is make it a
>separate control just below the grid (that's what I do on my forms)
>...

Thank you, Marc,

a seperate control will do fine and this is my approach too. But I'm
afraid, my problem is one step more primitive: how do i access the
DBGrid values to be calculated, and which event is the one to hook the
procedure to in an efficient way (having the calculation done only
when the grid is changed or displayed the first time)?

You see, I'm not too smart in delphi now, so maybe you could help me
with a piece of sample code?

Thanks again!

Bernd

Re:Show Column Sum in DBGrid?


Quote
In article <5n0jin$ki...@garion.telecom.at>, b.weik...@aon.at (B. Weikert) wrote:
>"Mark Bratcher" <mbra...@ix.netcom.com> wrote:

>>Well, I think the normal way to show a sum for a DBgrid is make it a
>>separate control just below the grid (that's what I do on my forms)
>>...

>Thank you, Marc,

>a seperate control will do fine and this is my approach too. But I'm
>afraid, my problem is one step more primitive: how do i access the
>DBGrid values to be calculated, and which event is the one to hook the
>procedure to in an efficient way (having the calculation done only
>when the grid is changed or displayed the first time)?

>You see, I'm not too smart in delphi now, so maybe you could help me
>with a piece of sample code?

I posted a grid control (TColossalGrid) to the Delphi Super Page the has a
footer where you can place the column totals.

John

------------------------------------------------
Big Brother is watching and keeping track of what
you post. I have removed my personal information
from the header and moved it here.

EMail Address:
|m.i.a.n.o @    |
|w.o.r.l.d.n.e.t . |
|a.t.t .|
|n.e.t |

Full Name:
-------------------
-J.o.h.n?M.i.a.n.o-
-------------------

Re:Show Column Sum in DBGrid?


Quote
In article <5n0jin$ki...@garion.telecom.at>, b.weik...@aon.at (B. Weikert) wrote:
>"Mark Bratcher" <mbra...@ix.netcom.com> wrote:

>>Well, I think the normal way to show a sum for a DBgrid is make it a
>>separate control just below the grid (that's what I do on my forms)
>>...

>Thank you, Marc,

>a seperate control will do fine and this is my approach too. But I'm
>afraid, my problem is one step more primitive: how do i access the
>DBGrid values to be calculated, and which event is the one to hook the
>procedure to in an efficient way (having the calculation done only
>when the grid is changed or displayed the first time)?

>You see, I'm not too smart in delphi now, so maybe you could help me
>with a piece of sample code?

I posted a grid control (TColossalGrid) to the Delphi Super Page the has a
footer where you can place the column totals.

John

------------------------------------------------
Big Brother is watching and keeping track of what
you post. I have removed my personal information
from the header and moved it here.

EMail Address:
|m.i.a.n.o @    |
|w.o.r.l.d.n.e.t . |
|a.t.t .|
|n.e.t |

Full Name:
-------------------
-J.o.h.n?M.i.a.n.o-
-------------------

Other Threads