Thanks for everyone's help.

Tom gave me an idea of using a previous balance field, which I am
currently looking into. Speed is really important, so using a previous
balances could be really useful. I will need to add the Balance Field
as a physical column rather than a calculated one - something I wanted
to avoid, but it will also solve other related issues I have too.

Glen, I had already looked into using a StringGrid but it's a lot of
work getting other parts of the application to work (eg. OnDataChange
etc), but thanks for the reply anyway.

Regards,

Ian

--- In [email protected], "Glenn B. Lawler" <[EMAIL PROTECTED]> wrote:
>
> Ian,
> 
> >I have a problem with a project I am working on. I have a database
> >table containing financial transactions:
> >
> >id    account    date    description    amount_in    amount_out
> >
> >I filter the table based on things like account, date ranges etc and
> >then show the results in a DBGrid. The user can click on a column to
> >change the sort. I need to show the current balance on each row so:
> >
> >balance = previous_balance + (amount_in - amount_out)
> >
> >This isn't a big problem until the user scrolls the grid or changes
> >the sort field, then the balance column changes as the balance on the
> >previous row is wrong.
> 
> If all you want to do is display the output in the grid without the
need to
> change the data, I would just use a TQuery and TStringGrid to display
> the data. Your loop that adds rows to the grid could calculate the
balance
> any way you want. If users need to change sort order, you can write your
> own code to handle clicks on the top row and either sort the loaded grid
> or just change the ORDER BY in the SQL and reload.
> 
> Glenn Lawler
> www.incodesystems.com
>


Reply via email to