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开发者_StackOverflow)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.
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
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;
精彩评论