Add column LISTVIEW

1

I have a listview component in my project, and it has a Column with multiple values entered. Anyone has any idea how I can add an entire column of the listview that only include values of type:

 300,00
 52,00
 100,00

Thanks for any help ....

    
asked by anonymous 30.08.2014 / 00:52

1 answer

2

This is 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 on Delphi7.

The ".Caption" accesses the value of the first column. If it is necessary to access others, ".SubItems [x]" should be used, remembering that "x" is equal to "column number" minus 2.

Examples:

  • The second column of the ListView is the first sub-iten and it has index "0" (zero)
  • The seventh column of the ListView would be accessed with ".SubItems [5]"
30.08.2014 / 02:45