DisplayRectSubItem lazarus / 31-LCL ---------------------------------------------------------------------- marconi · 2015-06-22 07:52 Hi, I'm trying to put a progressbar inside a listview item...I found some Delphi code which uses DisplayRect or DisplayRectSubItem functions of TListItem but, in both case, these functions always return a TRect with Left, Right, Top and Bottom set to zero (0,0,0,0). I'm using Lazarus 1.4.0 with Windows XP...any suggestions ? ---------------------------------------------------------------------- zeljko · 2015-06-22 08:22 Then it's bug in win32lcl (if that works with Delphi). Please fill an issue about it and attach example project. ---------------------------------------------------------------------- howardpc · 2015-06-22 09:06 This example (using DisplayRect, not DisplayRectSubItem which I have not tested) works well for me on Windows. Code: [Select]unit Unit1; {$mode objfpc}{$H+} interface uses   Classes, SysUtils, Forms, ComCtrls; type { TForm1 }   TForm1 = class(TForm)     ListView1: TListView;     procedure FormCreate(Sender: TObject);     procedure ListView1CustomDrawItem(Sender: TCustomListView; Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);   end; var   Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView; Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean); var   r: TRect;   pb: TProgressBar; begin   if not (sender is TCustomListView) or (Sender = nil) then Exit;   r:=Item.DisplayRect(drBounds);   pb:=TProgressBar(item.Data);   if (pb <> nil) then     begin       pb.SetBounds(r.Left + 50, r.Top, r.Right-r.Left, r.Bottom-r.Top);       pb.Position:=10*Succ(Item.Index);     end;   r.Right:=50;   Sender.Canvas.TextRect(r, 0, 0, Item.Caption); end; procedure TForm1.FormCreate(Sender: TObject); var   li: TListItem;   i: integer; begin   ListView1.OwnerDraw:=True;   for i:=0 to 7 do     begin       li:=ListView1.Items.Add;       li.Caption:=Format('Item# %d',[i]);       li.Data:=TProgressBar.Create(Self);       TProgressBar(li.Data).Parent:=ListView1;     end;   ListView1.Items.Add; end; end. ---------------------------------------------------------------------- marconi · 2015-06-24 08:47 Howardpc's code is working, I will check if it can be used with DisplayRectSubItem too. Thanks a lot ! EDITED--------- Works with  DisplayRectSubItem too, thanks again