Solved

Delphi1 DBGRID-Running Totals

Posted on 1999-01-06
1
244 Views
Last Modified: 2010-08-05
I'm using Delphi1 and have a DBgrid with cols 1 thru 7.  Data Entry is allowed in cols 2 thru 7.  I would like to generate totals for cols 2 thru 7 as data is entered into a cell.  Ideally, the totals would be displayed in a second grid.

Example code is very much appreciated.

bisrael@lfpress.com
0
Comment
Question by:bisrael
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
ZifNab earned 100 total points
ID: 1354946
Bisrael,

do you need to display it into a second dbgrid or stringgrid?

what you can do :

use a calculated field, which just sums up the columns you need and display this calculated field into the second dbgrid.

after every event (recordchange, insert, etc) calculate the sum of the columns and add these to a grid.


I guess you mean one, so I give you some source for that :

I've added in the fieldseditor of table1 all the fields + a calculated field

Ive added two grids and in one grid i only show the calculated field (columns property) I don't know anymore if this is available in D1. If not, then you've to make two tables pointing to the same datatable and then through the fieldseditor only show the calc field.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Db, DBTables, Grids, DBGrids;

type
  TForm1 = class(TForm)
    Table1: TTable;
    Table1SpeciesNo: TFloatField;
    Table1Category: TStringField;
    Table1Common_Name: TStringField;
    Table1SpeciesName: TStringField;
    Table1Lengthcm: TFloatField;
    Table1Length_In: TFloatField;
    Table1Notes: TMemoField;
    Table1Graphic: TGraphicField;
    Table1calc: TCurrencyField;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    DBGrid2: TDBGrid;
    procedure Table1CalcFields(DataSet: TDataSet);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Table1CalcFields(DataSet: TDataSet);
begin
 dataset.FieldByName('Calc').AsFloat :=
  dataset.FieldByName('Species No').AsInteger *
  dataset.FieldByName('Length_In').AsFloat
end;

end.

Regards, Zif.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question