TListItemSubItems (C++)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example requires only a blank form. All the other objects: TListView, TListColumns, TListItems are created dynamically. You must add comctrls to the uses defs file.

Code

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  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]);
  }
}

Uses