OnCustomDrawItem event of TListView doesn't seem to work lazarus / 31-LCL ---------------------------------------------------------------------- lazjump · 2016-03-14 13:06 Hello, OnCustomDrawItem event of TListView doesn't seem to work. To test, please put a ListView and set the ViewStyle property to vsReport, and put this code in the OnCustomDrawItem event: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   TListView(Sender).Canvas.Font.Style:=[fsStrikeOut]; The code would work fine in Delphi 7. Tested on Windows XP with the old Lazarus 1.4.0. And also tested on Windows 8 64 bit with CodeTyphon 5.70. ---------------------------------------------------------------------- lazjump · 2016-03-16 13:11 Since TListView is a common control, this looks like undesirable. Anyone have a workaround? ---------------------------------------------------------------------- lazjump · 2016-03-28 14:12 So anyone have a workaround? My need is very simple, I want to make the font of checked items in a List View become striked out. But this code don't work: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);begin  if Item.Checked then    TListView(Sender).Canvas.Font.Style:=[fsStrikeOut];end; Is this a bug, or wrong way to do it in Lazarus? ---------------------------------------------------------------------- balazsszekely · 2016-03-28 14:55 I'm afraid the component behaves differently in lazarus: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);begin  ListView1.OwnerDraw := True;  ListView1.Items.Add.Caption := 'Test';end; procedure TForm1.ListView1DrawItem(Sender: TCustomListView; AItem: TListItem;  ARect: TRect; AState: TOwnerDrawState);begin  with Sender.Canvas do  begin    Font.Size := 11;    Font.Name := 'Tahoma';    Font.Style := Sender.Canvas.Font.Style + [fsStrikeOut];    TextOut(ARect.Left + 2, ARect.Top + 2, AItem.Caption);  end;end;       PS: I would switch to virtual tree instead of you. ---------------------------------------------------------------------- lazjump · 2016-03-28 15:17 Thank you for your kind reply, GetMem. Yes it looks like ListView behaves differently in Lazarus & Delphi 7. I thought it would behave the same since it is a "common control". But it is not. I am aware of using OwnerDraw:=true and the OnDrawItem event. But there comes several problems with that; one is that the checkbox in the ListView must be painted manually. And there are several other problems (which I don't remember) when I tried to owner draw the List View. ---------------------------------------------------------------------- howardpc · 2016-03-28 15:49 You don't have to paint the checkbox manually (though you can if you wish). Try this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView;  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);var  lv: TCustomListView absolute Sender;begin  if not (Sender is TCustomListView) then    Exit;  if Item.Checked then begin    lv.Canvas.Font.Style:=lv.Font.Style + [fsBold, fsStrikeOut];    lv.Canvas.TextRect(Item.DisplayRect(drIcon), 25, 5 + Item.Position.Y, Item.Caption);    DefaultDraw:=False;  end;end; ---------------------------------------------------------------------- lazjump · 2016-03-29 09:06 Hi howardpc, Thank you. But that doesn't seem to work with the old Lazarus 1.4.0 (Windows XP) and also with CodeTyphon 5.70 (Windows 8 64 bit) ---------------------------------------------------------------------- howardpc · 2016-03-29 10:16 Yes, my example was compiled on Linux (64-bit). Ironic that customising the Windows widgetset implementation of GUI controls first introduced in Windows does not yet work as expected on Windows, but does on other OSs. I haven't tried this exercise with a trunk Lazarus on a recent Windows, but Laz 1.4 and CodeTyphon may well differ from the behaviour of Lazarus trunk Win 32/64 (or even the 1.6 release).