views:

101

answers:

1

hello, I've a Tlistview with 3 columns, I need from Tcollection object as this follow

FListeDispoProduit := TListeDispoProduit.Create(TProduit);

  with (FListeDispoProduit) do
  begin
    with TProduit(Add) do
    begin
      Name := 'Produit 01';
      CIP := 'A001';
      StockQty := 3;
    end;

But when I try to put this object into the Tlistview only the first column (Name)is populate I write this:

for i := 0 to FListeDispoProduit.Count -1 do
     Tlistview1.Items.Insert(i).Caption := TProduit(FListeDispoProduit.Items[i]).Name;

I need fill those 3 columns (Name,cip,StockQty ), how can I do this?

Thank you.

hope I be clear.

+1  A: 
for i := 0 to FListeDispoProduit.Count -1 do  
   with ListView1.Items.Add() do begin
      Caption :=  TProduit(FListeDispoProduit.Items[i]).Name;  
      SubItems.Add(TProduit(FListeDispoProduit.Items[i]).CIP);   
      SubItems.Add(IntToStr(TProduit(FListeDispoProduit.Items[i]).StockQty));  
   end; 

And add more columns in TListView

Im0rtality
Thank you very much Im0rtality.
I prefer to avoid WITH blocks. Instead, I use a var li: TListItem; Then in the for loop, says li := ListView1.Items.Add(); li.Caption... li.SubItems.Add... etc.
Phil Gilmore
I also recommend using ListView1.Items.BeginUpdate and ListView1.Items.EndUpdate to wrap loops which insert a large number of items. It disables the ui temporarily to speed things up.
Phil Gilmore
`begin` should really be on a new line. Otherwise it looks to the trained eye like only `Caption := ...` is inside the `with` statement. Also Phile Gilmore's *second* comment is **very** important.
Andreas Rejbrand