Solved

Delphi1 DBGRID-Running Totals

Posted on 1999-01-06
1
237 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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 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

16 Experts available now in Live!

Get 1:1 Help Now