使用标准的TListView组件(ViewStyle = vsReport),我附加了一个TImageList,并成功地将图像添加到第一列(Item.ImageIndex := 0)和后续列(Items[0].SubItemImages[1] := 1).
如果我然后将CheckBoxes属性设置为True,则SubItems上的图像将消失.主图像保留(由一个设置Item.ImageIndex),但SubItems丢失了他们的图像.
我也注意到OnGetSubItemImage事件不会发生时CheckBoxes = True
有没有人知道这方面的方法?
这是一个非常老的错误,当您激活CheckBoxes属性时,将禁用TListView控件上的LVS_EX_SUBITEMIMAGES和LVS_EX_INFOTIP样式.
您可以使用此解决方法来修复此错误.
1)禁用listview中的checkbox属性
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;
Run Code Online (Sandbox Code Playgroud)
3)最终结果是
替代文字http://i50.tinypic.com/20hrfhd.png