TimeIsNear
TimeIsNear

Reputation: 755

Delphi 7: how to fill a Tlistview

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.

Upvotes: 3

Views: 9289

Answers (2)

Edijs Kolesnikovičs
Edijs Kolesnikovičs

Reputation: 1695

Procedure TForm1.FillListView;
var
  i: Integer;
  ListItem: TListItem;
begin
  try
    ListView1.Items.BeginUpdate;
    try
      ListView1.Clear;
      for i := 1 to 9 do
        with ListView1 do
          begin
            ListItem := ListView1.Items.Add;
            Listitem.Caption := 'Caption '+IntToStr(i);
            ListItem.SubItems.Add('Subitem1 '+IntToStr(i));
            ListItem.SubItems.Add('Subitem2 '+IntToStr(i));
          end;
    finally
      ListView1.Items.EndUpdate;
    end;
  except
    on E: Exception do
      MessageDlg(PWideChar(E.Message), TMsgDlgType.mtError, [TMsgDlgBtn.mbOK], 0);
  end;
end;

Upvotes: 1

Im0rtality
Im0rtality

Reputation: 3533

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

Upvotes: 8

Related Questions