ListView

Hi all,

i'm trying ListView and want to manage it by code, how we fill several columns ?

is there an example with ListView and set columns ?

i try this but only the second column is set :
i := 0;
while not end do
begin
   ListView.Items.Add;
   ListView.Items.SubItems.Add('abc');
   ListView.Items.SubItems.Add('def');
   Inc(i);
end;

only 'abc' appears in the second column...

Thanks

The correct way to do this is:

while not end do
begin
   with ListView.Items.Add do
   begin
      Caption := 'col 0';
      SubItems.Add('col 1');
      SubItems.Add('col 2');
   end;
   Inc(i);
end;

Thanks for your help Bruno

But sorry i d tried what you wrote but does the same thing ( only display the first 'SubItems.Add' at the second column )

if i put only one SubItems.Add, it display at second column... why ?

my first try was this :

i := 0;
while not end do
begin
   ListView.Items.Add;
   ListView.Items.SubItems.Add('abc');
   ListView.Items.SubItems.Add('def');
   Inc(i);
end;

it doesn't work too, i thougth that 'Items.Add' create one row and 'SubItems.Add' create one cell in one column but it seems not true...

The first 'SubItem.Add' is only dislpay and at the second column ( not the first ) and it seems that only one 'SubItem.Add' is display not the others ( even if i add others )


It's clear that i'm wrong but i can't find the correct way...


Drop a default TMSFMXListView on the form and copy & paste this code in your form and you should see it does work as expected:


procedure TForm1.FormCreate(Sender: TObject);
begin
  TMSFMXListView1.Columns.Add;
  TMSFMXListView1.Columns.Add;
  TMSFMXListView1.Columns.Add;

  with TMSFMXListView1.Items.Add do
  begin
    Text := 'col 0';
    SubItems.Add('col 1');
    SubItems.Add('col 2');
  end;

  with TMSFMXListView1.Items.Add do
  begin
    Text := 'col 0*';
    SubItems.Add('col 1*');
    SubItems.Add('col 2*');
  end;
end;

Ok it works thanks.

Where can i find documentation about TMSListView ?

We've designed it to be interface compatible with the standard VCL TListView, so please consult this information if its use is not clear.

Ok but with VLC TListView we can adjust width of column but not with TTMSFMXListView ?

TMSFMXListView1.Columns[index].Width : doesn't exist ?

Sorry, we haven't exposed Width yet.
We'll consider that for a future update.