Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Adding headers to TListView programmatically

During today’s Delphi, C++Builder and RAD Studio 10 Seattle launch webinar, I got a question on how to add headers to TListView programmatically instead of using LiveBindings with a data source.

Here is a quick code snippet showing how to programmatically add TListView headers.

procedure TListViewHeaders.FormCreate(Sender: TObject);
var
  Group, Item: Integer;
begin
  for Group in [1..4] do
  begin
    with ListView1.Items.Add do
    begin
      Text := Format('Header %d', [Group]);
      Purpose := TListItemPurpose.Header;
    end;
     for Item in [1..10] do
     ListView1.Items.Add.Text := Format('Regular item %d.%d', [Group, Item]);
  end;
end;

 

Exit mobile version