[Lazarus] How to populate a TListView programatically

Aruna Hewapathirane aruna.hewapathirane at gmail.com
Thu Nov 17 02:30:47 CET 2022


On Wed, Nov 16, 2022 at 6:29 PM Werner Pamler via lazarus <
lazarus at lists.lazarus-ide.org> wrote:

> Am 17.11.2022 um 00:03 schrieb Aruna Hewapathirane via lazarus:
> > Does anyone have any example code that populates a Listview component
> > through code please?
> procedure TForm1.FormCreate(Sender: TObject);
> var
>    item: TListItem;
>    i: Integer;
> begin
>    for i := 0 to 9 do
>    begin
>      item := ListView1.Items.Add;
>      item.Caption := 'Item ' + IntToStr(i);
>      item.SubItems.Add('Subitem ' + IntToStr(i) + '/1');
>      item.SubItems.Add('Subitem ' + IntToStr(i) + '/2');
>      item.ImageIndex := i;
>      item.SubItemImages[0] := i+1;
>      item.SubItemImages[1] := i+2;
>    end;
> end;
> --
>

This is exactly what I was looking for. It is the subitems that was giving
me a real problem.
Thank you very much Werner.



> _______________________________________________
> lazarus mailing list
> lazarus at lists.lazarus-ide.org
> https://lists.lazarus-ide.org/listinfo/lazarus
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20221116/2be7b1ba/attachment.htm>


More information about the lazarus mailing list