Board index » delphi » Total Fields from DBgrid, Ttable, Tquery, Tdataset

Total Fields from DBgrid, Ttable, Tquery, Tdataset

There must be a simple way to place a DBgrid on a form, and allow the
user to filter the table pointed to by the DBgrid, and also have a total

field on the form that will give a persistent total of the 'filtered
dates' that the user sees in the grid.  In Paradox, this was very easily

done with a Tcursor type that would point to the table in memory and let

you navigate through the table behind the scenes without the view in the

grid ever changing.

This must be very simple and I must just be overlooking something so
simple it ought to reach out and bite me, but I have not discovered it
yet.

   I half-way achieved the same result by defining a second table, and
navigating totals through that table which is not connected to a grid,
but I want to keep the same filter that the user sets.  I guess I could
pass the filter, or range to the second table, but it seems like it
should be much easier than that.

Please help me.

hartm...@geneseo.net

John

 

Re:Total Fields from DBgrid, Ttable, Tquery, Tdataset


Quote
In article <3490B3D1.271B2...@geneseo.net>, John Hartman wrote:
> In Paradox, this was very easily
> done with a Tcursor type that would point to the table in memory and
let
> you navigate through the table behind the scenes without the view in
the
> grid ever changing.

See DisableControls/EnableControls.

Also, please comply with Borland Newgroup Guidelines regarding not
posting messages to multiple newsgroups.

Re:Total Fields from DBgrid, Ttable, Tquery, Tdataset


Hi John,

I don't know how handy you are with SQL, but you could easily
set up a second TDataSet as a TQuery object. Here's what the
SQL might look like:

SELECT SUM(Field1) AS f1Total, SUM(Field2) AS f2Total
FROM MyTableName WHERE Field3=30;

Of course you'll have to do a better job than I did. But if you
toggle the Active property on this query every time the filter
changes, you'll have you're total and you can forget the cursor
and all the other overhead. Depending on what you're doing, you
could set the DataSource property on the TQuery and you might not
even have to toggle the Active property.

Of course you'd have to link a text box to the TQuery to show totals.

I hope this helps.

Jim Baiely
TeamB

Quote
John Hartman wrote:

> There must be a simple way to place a DBgrid on a form, and allow the
> user to filter the table pointed to by the DBgrid, and also have a total

> field on the form that will give a persistent total of the 'filtered
> dates' that the user sees in the grid.  In Paradox, this was very easily

> done with a Tcursor type that would point to the table in memory and let

> you navigate through the table behind the scenes without the view in the

> grid ever changing.

> This must be very simple and I must just be overlooking something so
> simple it ought to reach out and bite me, but I have not discovered it
> yet.

>    I half-way achieved the same result by defining a second table, and
> navigating totals through that table which is not connected to a grid,
> but I want to keep the same filter that the user sets.  I guess I could
> pass the filter, or range to the second table, but it seems like it
> should be much easier than that.

> Please help me.

> hartm...@geneseo.net

> John

Re:Total Fields from DBgrid, Ttable, Tquery, Tdataset


You need to have a OnDataChange event handler in the DataSource for the
table with the filter.

In that routine, get a bookmark to the current row, calculate the sum,
and restore your row position to the bookmark.

Don't forget to disable the controls before and enable them after, so
that the grids won't scroll while you do this.

I think that's it.

--
------
Mark Cashman, creator of The Temp{*word*203}Doorway at
http://www.geocities.com/~mcashman
- Original digital art, writing, and more -
Author of SF novels available at...
http://www.infohaus.com/access/by-seller/The_Temporal_Doorway_Storefront
------

Other Threads