Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delphi1 DBGRID-Running Totals

Posted on 1999-01-06
1
Medium Priority
?
249 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 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 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