RAD Studio VCL Reference
|
Creates a new list item and adds it to the list view control.
function Add: TListItem;
__fastcall TListItem Add();
Call Add to add a new list item to the end of the list. Add returns the newly created TListItem object.
To create an item and insert it into the beginning or middle of the list, use the Insert method instead.
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); 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) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|