2015-09-16 44 views
3

我使用Delphi XE,我想使標準ListView的行爲看起來像我想要的。 我想列表視圖是vsReport,所以我可以爲我的項目組。 在設計時,我爲每個組創建了列(名爲Topic的一列),兩個組和幾個項目。如何防止ListView標題遮擋第一組的頂部?

在設計時,ListView看起來不錯,但是在運行時,我的第一組在某種程度上隱藏在列標題下。以下是圖像:

在設計時:

enter image description here

在運行時:

enter image description here

,這裏是我的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 

如何防止這種情況發生?

回答

2

即使在Delphi 10 Seattle中也存在此行爲。我不確定是什麼原因造成的,但是可以通過對列表視圖屬性進行重大更改,然後恢復該更改來解決此問題。這似乎足以讓列表視圖迎頭趕上。例如,這就足夠了:

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

但是,這是有點過於頂部。深入研究這些代碼的作用,它重新創建窗口的關鍵。這是可以做到這樣的:

type 
    TProtectedHackListView = class(TListView); 

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

甚至重建形式,這反過來將重新孩子:

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

的'RecreateWnd()'上只是'TListView'就足夠了。改變'ViewStyle'是矯枉過正的,正如重新創建Form窗口及其所有子控件一樣。 –

+0

謝謝你們兩位。雷米Lebeau,您的評論也非常有幫助。謝謝 – user1137313

+0

作爲一個測試,我創建了一個'TForm',它的'CreateWnd()'方法直接調用與'TListView'相同的API,並且生成的ListView不會出現問題。很奇怪。也許有一些額外的'TListView'正在干擾底層窗口,以管理其內容相對於其內置頭控件的方式。 –

相關問題