RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TListItem.SubItems Property

Contains any strings that appear as subitems to the list item.

Pascal
property SubItems: TStrings;
C++
__property TStrings SubItems;

Use SubItems to add strings that appear in the additional columns to the right of the list view item when the list view's ViewStyle property is vsReport. The TStrings object that implements the SubItems property is created when the list item is created. To the methods of the SubItems object to add or delete subitems.

Note: Subitems are only visible when the list view's ViewStyle property is set to vsReport.
 

C++ Examples: 

 

/*
This example requires only a blank form.  All other objects:
TListView, TListColumns, TListItems, are created dynamically.
You must add comctrls to the uses defs file.
*/
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  const char Names[6][2][10] = 
   {{"Rubble","Barny"},
    {"Michael", "Johnson"},
    {"Bunny", "Bugs"},
    {"Silver", "HiHo"},
    {"Simpson", "Bart"},
    {"Squirrel", "Rocky"}};

  TListColumn  *NewColumn;
  TListItem  *ListItem;
  TListView   *ListView = new TListView(this); // The owner will clean this up.

  ListView->Parent = this;
  ListView->Align = alClient;
  ListView->ViewStyle = vsReport;
  NewColumn = ListView->Columns->Add();
  NewColumn->Caption = "Last";
  NewColumn = ListView->Columns->Add();
  NewColumn->Caption = "First";
  for (int i = 0; i < 6; i++)
  {
    ListItem = ListView->Items->Add();
    ListItem->Caption = Names[i][0];
    ListItem->SubItems->Add(Names[i][1]);
  }
}

 

Delphi Examples: 

{
This example requires only a blank form.  All other objects:
TListView, TListColumns, TListItems, are created dynamically.
You must add comctrls to the uses clause of the unit file.
} 
procedure TForm1.FormCreate(Sender: TObject);
const
  Names: array[0..5, 0..1] of string = (
    ('Rubble', 'Barney'),
    ('Michael', 'Johnson'),
    ('Bunny', 'Bugs'),
    ('Silver', 'HiHo'),
    ('Simpson', 'Bart'),
    ('Squirrel', 'Rocky')
    );

var
  I: Integer;
  NewColumn: TListColumn;
  ListItem: TListItem;
  ListView: TListView;
begin
  ListView := TListView.Create(Self);
  with ListView do
  begin
    Parent := Self;
    Align := alClient;
    ViewStyle := vsReport;

    NewColumn := Columns.Add;
    NewColumn.Caption := 'Last';
    NewColumn := Columns.Add;
    NewColumn.Caption := 'First';

    for I := Low(Names) to High(Names) do
    begin
      ListItem := Items.Add;
      ListItem.Caption := Names[I][0];
      ListItem.SubItems.Add(Names[I][1]);
    end;
  end;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!