开发者

TListView with CheckBoxes and SubItemImages

开发者 https://www.devze.com 2022-12-21 01:48 出处:网络
Using the standard TListView component (ViewStyle = vsReport), I have attached a TImageList and have successfully added images to both the first column (Item.ImageIndex := 0) and to the subsequent col

Using the standard TListView component (ViewStyle = vsReport), I have attached a TImageList and have successfully added images to both the first column (Item.ImageIndex := 0) and to the subsequent columns (Items[0].SubItemImages[1] := 1).

If I then set the CheckBoxes property to True, the images on SubItems disappear. The main image remains (the one set by Item.ImageIndex) but the SubItems lose开发者_如何转开发 their images.

I have also noticed that the OnGetSubItemImage event doesn't fire when CheckBoxes = True

Does anyone know of a way around this?


this is a very old bug, when you activate the CheckBoxes property would disable the LVS_EX_SUBITEMIMAGES and LVS_EX_INFOTIP styles on the TListView control.

you can use this workaround for fix this bug.

1) Disable the checkbox property in the listview

2) Put this code (Tested in Delphi 7 and windows 7) in your form .

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) and the final result is

TListView with CheckBoxes and SubItemImages


Well this doesn't help particularly, but the TMS TAdvListView component handles it with its SubImages property. Set this to True and I can have Checkboxes and sub item images. I'm sure there's a lot of good work going on behind the scenes. At least this moves me forward.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号