Jhonjhon_123
Jhonjhon_123

Reputation: 288

List view control drawn incorrectly when groups are present

I was experimenting with list view groups, and it turns out the control displays incorrectly when the application starts.

Original form

As soon as I resize the form it displays correctly:

Resized form

I do not understand what is happening. Can anyone explain?

Upvotes: 2

Views: 365

Answers (1)

David Heffernan
David Heffernan

Reputation: 612954

It's a bug in the Delphi control which I have reproduced. I'm not sure yet what causes the bug. I have submitted this to Quality Central as QC#101104.

I found a simple workaround by adding the following code to the form's OnShow event.

ListView1.Align := alNone;
ListView1.Align := alClient;

The following DFM file is enough to demonstrate the problem:

object MyForm: TMyForm
  Left = 0
  Top = 0
  ClientHeight = 300
  ClientWidth = 635
  object ListView1: TListView
    Left = 200
    Top = 96
    Width = 250
    Height = 150
    Align = alClient
    Columns = <
      item
        Caption = 'Column'
      end>
    Groups = <
      item
        Header = 'Group header'
        GroupID = 0
      end>
    Items.ItemData = {
      052A0000000100000000000000FFFFFFFFFFFFFFFF0000000000000000000000
      000854006800650020006900740065006D00}
    GroupView = True
    ViewStyle = vsReport
  end
end

It turns out that another way to resolve the problem is to move the ViewStyle entry in the DFM file so that it appears before the Items entry. So yet another workaround for the problem would be to add the items at runtime. In fact this probably explains why this bug has not been found since I bet that the overwhelming majority of list view code adds the items at runtime.

Upvotes: 4

Related Questions