[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 581
  • Last Modified:

DELPHI - cxrid column value

hi,

normally use the database queries, but now I need to work directly on the grid, use cxGrid.

How do I calculate the sum of the values ¿¿of all rows contained in a column?
0
danz67
Asked:
danz67
  • 3
1 Solution
 
ThommyCommented:
Summing multiple selected rows in a DBGrid
http://delphi.about.com/od/usedbvcl/a/tdbgrid.htm

You can implement it the same way with in a cxgrid...
0
 
ThommyCommented:
0
 
danz67Author Commented:
I need to know the value calculated in a column for all rows
and the result must be displayed in a label
0
 
ThommyCommented:
Replace second parameter of function GetValue(i,3) with the index of your grid column (starting with 0).

Make sure that the column you want to sum only contains numeric values, otherwise you will get an error!!!


var
  i:integer;
  sum : integer 
begin
  for i:=0 to cxGrid1.DataController.RecordCount-1 do begin
    sum:=sum+cxGrid1.DataController.GetValue(i,3);
  end;
  label1.caption:=inttostr(sum);
end;

Open in new window

0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now