Solved

Delphi1 DBGRID-Running Totals

Posted on 1999-01-06
1
239 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
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

803 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