Rosanna Trevisan
Rosanna Trevisan

Reputation: 452

Delphi listview change header text

I have this simple form:

enter image description here

and I use this code to add items:

FList.BeginUpdate;
  try
    Flist.Items.Clear;

    for LJsonValue in LJsonArr do
      begin
        Item := FList.Items.Add;

        Item.Text := 'some value';

        //What to do?
        FList.??.??.HeaderText := 'Header';
      end;
  finally
    FList.EndUpdate;
  end;

How can I change the header and the footer? I have been able to google only the above solution. The above code only sets some value instead of Item Text but I cannot change Header Text and Footer Text.

Upvotes: 3

Views: 3803

Answers (2)

Alvaro
Alvaro

Reputation: 1

procedure TFrmPrincipal.AddHeader(categoria: string);
var
  item: TListViewItem;
begin
  item := lvProdutos.Items.Add;
  item.Purpose := TListItemPurpose.Header;
  item.Text := categoria;
end;

Credit to: 99Coders (https://www.youtube.com/watch?v=o2qEEhn_2Tc).

Upvotes: 0

Peter Wolf
Peter Wolf

Reputation: 3830

Headers and footers are regular instances of TListViewItem except they have their Purpose property set to TListItemPurpose.Header or TListItemPurpose.Footer. This property instructs the component to render those items using special appearances - see properties ItemAppearance and ItemAppearanceObjects of TListView.

You can add header(s) and footer(s) at run-time (assumed using standard appearance):

Item := Flist.Items.Add;
Item.Text := 'Header';
Item.Purpose := TListItemPurpose.Header;

Flist.Items.Add.Text := 'Item 1';
Flist.Items.Add.Text := 'Item 2';

Item := Flist.Items.Add;
Item.Text := 'Footer';
Item.Purpose := TListItemPurpose.Footer;

Upvotes: 4

Related Questions