bdn.borland.com

Article #28298: Loading a TListView component that contains SubItems.

QUESTION:

How do I load the SubItems of a TListView component?

ANSWER:

Add a TListView to a form. Next, right click the ListView components to envoke the sub-menu, and select Columns Editor. Add two columns and set the Width property to 300. In the TlistView properties set the ViewStyle to vsReport. Drop a TButton on the form and add the code sample below to the button's OnClick event.

procedure TfrmMain.Button1Click(Sender: TObject);
var
  NewItem: TListItem;
begin
  NewItem := ListView1.Items.Add;
  NewItem.Caption := 'FirstItem';  //some string.
  NewItem.SubItems.Add('SecondItem'); // next string.
end;

Last Modified: 05-FEB-02