Solved

Delphi1 DBGRID-Running Totals

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi 10 Seattle Dataset Actions 5 78
add combobox item based on numbers 9 119
find a node in VST 2 63
Magic Software info 18 124
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…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

914 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now