user1137313
user1137313

Reputation: 2410

How do I prevent a ListView header from obscuring the top of the first group?

I use Delphi XE and I want to make a standard ListView behave and look like I want it. I want the listview to be vsReport so I can have Groups for my items. At design time I created the columns (one column named Topic), two groups, and a few items for each group.

At design time the ListView looks great, but at runtime, my first group is somehow partially hidden under the column caption. Here are the images:

At designtime:

enter image description here

At runtime:

enter image description here

and here is my DFM

object Form2: TForm2
  Left = 326
  Top = 150
  Caption = 'Form2'
  ClientHeight = 636
  ClientWidth = 1289
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object ListView1: TListView
    Left = 0
    Top = 0
    Width = 205
    Height = 636
    Align = alLeft
    Columns = <
      item
        Caption = 'Topic'
        Width = 200
      end>
    ColumnClick = False
    DoubleBuffered = True
    FullDrag = True
    Groups = <
      item
        Header = 'First group'
        GroupID = 0
        State = []
        HeaderAlign = taLeftJustify
        FooterAlign = taLeftJustify
        Subtitle = 'Options bellow'
        TitleImage = 1
      end
      item
        Header = 'Settings'
        GroupID = 1
        State = [lgsNormal]
        HeaderAlign = taLeftJustify
        FooterAlign = taLeftJustify
        Subtitle = 'Other options here'
        TitleImage = 0
      end>
    HideSelection = False
    HotTrack = True
    HotTrackStyles = [htUnderlineCold, htUnderlineHot]
    Items.ItemData = {
      059E000000030000000000000000000000FFFFFFFF0000000000000000000000
      000A4600690072007300740020006900740065006D000100000001000000FFFF
      FFFF0000000000000000000000000B5300650063006F006E0064002000690074
      0065006D000200000002000000FFFFFFFF000000000100000000000000134600
      69007300720074002000730065007400740069006E0067007300200069007400
      65006D00}
    GroupView = True
    RowSelect = True
    ParentDoubleBuffered = False
    ShowWorkAreas = True
    TabOrder = 0
    ViewStyle = vsReport
    OnClick = ListView1Click
    ExplicitTop = 8
    ExplicitHeight = 497
  end
end

How do I prevent this from happening?

Upvotes: 3

Views: 933

Answers (1)

David Heffernan
David Heffernan

Reputation: 612954

This behaviour is present even in Delphi 10 Seattle. I'm not sure what causes it but you can work around it by making a significant change to the list view properties, and then reverting that change. That seems to be enough to get the list view to catch up. For instance, this will suffice:

procedure TForm1.FormCreate(Sender: TObject);
begin
  ListView1.ViewStyle := vsIcon;
  ListView1.ViewStyle := vsReport;
end;

But that's somewhat over the top. Digging in to what effect this code has, the key thing it does it to recreate the window. Which can be done like this:

type
  TProtectedHackListView = class(TListView);

procedure TForm1.FormCreate(Sender: TObject);
begin
  TProtectedHackListView(ListView1).RecreateWnd;
end;

Or even recreating the form, which in turn will recreate the children:

procedure TForm1.FormCreate(Sender: TObject);
begin
  RecreateWnd;
end;

Upvotes: 2

Related Questions