Follows part of the source code of a form I created to test the solution.
type
TfrmPrincipal = class(TForm)
lvLista: TListView;
btnSoma: TButton;
procedure btnSomaClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmPrincipal: TfrmPrincipal;
implementation
{$R *.dfm}
procedure TfrmPrincipal.btnSomaClick(Sender: TObject);
var
dSoma : double;
i : integer;
begin
dSoma := 0;
for i := 0 to MyListView.Items.Count - 1 do begin
dSoma := dSoma + StrToFloatDef( MyListView.Items[ i ].Caption, 0 );
end;
ShowMessage( FloatToStr( dSoma ) );
end;
Tested in Delphi7.
". Caption" accesses the value of the first column.
If it is necessary to access others, it should be used ". Subitems[x]", remembering that "x" is equal to "column number" minus 2.
Examples:
- The second column of Listview is the first sub-iten and this has index
"0" (zero)
- The seventh column of Listview would be accessed with ". Subitems[5]"
Do not add in listview. Add when inserting in listview from the variables that populate the items in the loop, then you just add the line of the total if you want to display on the screen (or use the value elsewhere in the software as you wish).
– Bacco