2010-02-25 55 views
1

使用標準TListView組件(ViewStyle = vsReport),我附加了一個TImageList,併成功將圖像添加到第一列(Item.ImageIndex := 0)和後續列(Items[0].SubItemImages[1] := 1)。帶有複選框和子項目圖像的TListView

如果我然後將CheckBoxes屬性設置爲True,SubItems上的圖像消失。主要圖像保持不變(由Item.ImageIndex設置),但子項失去其圖像。

我也注意到,OnGetSubItemImage不會觸發事件時CheckBoxes = True

有誰知道解決的辦法?

+2

據我知道你不能,因爲窗戶的標準控制本身使用圖片爲那些「複選框」有他們兩個,因此你將不得不老闆繪製每個列表項目 – zz1433 2010-02-25 19:58:28

回答

7

這是一個非常古老的錯誤,當您激活CheckBoxes屬性將禁用TListView控件上的LVS_EX_SUBITEMIMAGES和 LVS_EX_INFOTIP樣式。

您可以使用此解決方法修復此錯誤。

1)禁止在ListView

2)在您的形式將這個代碼(在Delphi 7測試和Windows 7)的複選框屬性。

const 
    LVM_FIRST =$1000; 
    LVS_EX_SUBITEMIMAGES   = $00000002; 
    LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54; 
    LVM_GETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 55; 


function ListView_GetExtendedListViewStyle(LVWnd: HWnd): DWORD; 
begin 
    Result := SendMessage(LVWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0); 
end; 

function ListView_SetExtendedListViewStyle(LVWnd: HWnd; ExStyle: LPARAM): DWORD; 
begin 
    Result := SendMessage(LVWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, ExStyle); 
end; 


procedure TForm1.FormCreate(Sender: TObject); 
begin 
ListView1.Checkboxes:=True;//Activate the checkbox in the listview 
ListView_SetExtendedListViewStyle(ListView1.Handle,ListView_GetExtendedListViewStyle(ListView1.Handle) OR LVS_EX_SUBITEMIMAGES); //Activate the LVS_EX_SUBITEMIMAGES style. 
end; 

3)最終的結果是

alt text http://i50.tinypic.com/20hrfhd.png

+0

非常棒的答案,謝謝。 – 2010-02-26 08:47:33

+0

hw是否在應用樣式之後將圖像添加到此處? – Smith 2012-11-29 21:43:40

0

嗯,這並沒有特別的幫助,但TMS TAdvListView組件使用它的SubImages屬性來處理它。設置爲True,我可以有複選框和子項目圖像。我相信幕後有很多很好的工作。至少這讓我感動。