Jump to content
William23668

Adding items to ListView

Recommended Posts

Hi

 

It is FMX app but I just want to test adding items from code in Windows so I used that code from here

 

var
LItem: TListItem;
begin
  LItem := TListItem.Create(ListViewContacts.Items);
  LItem.Caption := 'new item';

I added "Commctrl" to uses clause but "Caption" is not defined, why ?

Edited by William23668

Share this post


Link to post
  FMX.ListView.Types,
  FMX.ListView.Appearances,
  FMX.ListView.Adapters.Base,
  FMX.ListView;

type
  TForm1 = class(TForm)
    ListView1: TListView;
    procedure FormCreate(Sender: TObject);
  ...
  
implementation

{$R *.fmx}

procedure TForm1.FormCreate(Sender: TObject);
var
  LVItem: TListViewItem;
begin
  LVItem      := ListView1.Items.Add;
  LVItem.Text := 'hello';
end;

end.

 

Edited by programmerdelphi2k

Share this post


Link to post
  Vcl.ComCtrls;

type
  TForm1 = class(TForm)
    ListView1: TListView;
    procedure FormCreate(Sender: TObject);
...

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  MyListItem: TListItem; // VCL
begin
  MyListItem         := ListView1.Items.Add;
  MyListItem.Caption := 'hello';
end;

end.

 

Edited by programmerdelphi2k

Share this post


Link to post

 

 

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  System.Variants, System.Permissions, FMX.Types, FMX.Controls, FMX.Forms,
  FMX.Graphics, FMX.Dialogs, Vcl.ComCtrls, Commctrl,
  FMX.AddressBook.Types, FMX.AddressBook, FMX.StdCtrls, FMX.SearchBox,
  FMX.Layouts, FMX.ListBox, FMX.Controls.Presentation, FMX.Edit, FMX.TabControl,
  FMX.Platform, System.Actions, FMX.ActnList, FMX.ListView.Types,
  FMX.ListView.Appearances, FMX.ListView.Adapters.Base, FMX.ListView,
  FMX.StdActns, FMX.MediaLibrary.Actions, FMX.Objects, FMX.Surfaces;
  
  ....

procedure TForm1.FormShow(Sender: TObject);
var
LItem: TListItem;
begin
  LItem := TListItem.Create(ListViewContacts.Items);
  LItem.Text := 'new item';

@programmerdelphi2k thanks but still same error.

 

image.thumb.png.19dc9230e97bc6ffceb2a8003d8b5d52.png

Edited by William23668

Share this post


Link to post

you cannot use TListIem.Create in FMX.

You should use 

var
  LVItem: TListViewItem;
begin
  LVItem      := ListView1.Items.Add;
  LVItem.Text := 'hello';
end;
  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×