RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TListColumn.Caption Property

Specifies the text that appears at the top of the column.

Pascal
property Caption: string;
C++
__property AnsiString Caption;

Use Caption to label the type of item that appears in the column. If the list view control's ViewStyle and ShowColumnHeaders properties are set to vsReport and true, respectively, the value of Caption appears at the top of the column.  

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!