<div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Hi Howard,</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Many thanks for your reply.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">That does seem to work, but my subitems and images don't seem to be displayed now?</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Would you mind giving me a further pointer as to how to display the images, and the subitems in the same colour?</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Thanks</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">Richard</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 15 September 2014 16:42, Howard Page-Clark <span dir="ltr"><<a href="mailto:hdpc@talktalk.net" target="_blank">hdpc@talktalk.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 15/09/2014 13:10, Richard Mace wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi All,<br>
I just want to make sure that I am not doing anything wrong here, please<br>
can somebody give me a little code example of how to correctly set the<br>
font to bold and a differnet colour in a listview entry?<br>
</blockquote>
<br></span>
I wouldn't claim the following is 'correct', but it works on Windows using TListView's OnCustomDrawItem() event.<br>
<br>
Howard<br>
<br>
==code==<br>
<br>
unit mainListviewOwnerDraw;<br>
<br>
{$mode objfpc}{$H+}<br>
<br>
interface<br>
<br>
uses<br>
  Classes, SysUtils, Forms, Graphics, ComCtrls, LCLType, StdCtrls;<br>
<br>
type<br>
  TForm1 = class(TForm)<br>
    ListView1: TListView;<br>
    procedure FormCreate(Sender: TObject);<br>
    procedure ListView1CustomDrawItem(<u></u>Sender: TCustomListView; Item: TListItem;<br>
      State: TCustomDrawState; var DefaultDraw: Boolean);<br>
  end;<br>
<br>
var<br>
  Form1: TForm1;<br>
<br>
implementation<br>
<br>
{$R *.lfm}<br>
<br>
procedure TForm1.FormCreate(Sender: TObject);<br>
var<br>
  li: TListItem;<br>
  lc: TListColumn;<br>
  i: Integer;<br>
begin<br>
  ListView1.ViewStyle:=vsReport;<br>
  ListView1.OwnerDraw:=True;<br>
  lc:=TListColumn.Create(<u></u>ListView1.Columns);<br>
  lc.Caption:='Select an item to show custom draw:';<br>
  lc.Width:=ListView1.Canvas.<u></u>TextWidth(lc.Caption) + 20;<br>
  for i:=0 to 4 do begin<br>
    li:=TListItem.Create(<u></u>ListView1.Items);<br>
    li.Caption:=Format('Item number %d',[i]);<br>
    ListView1.Items.AddItem(li);<br>
  end;<br>
end;<br>
<br>
procedure TForm1.<u></u>ListView1CustomDrawItem(<u></u>Sender: TCustomListView;<br>
  Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);<br>
var<br>
  rct: TRect;<br>
begin<br>
  DefaultDraw:=False;<br>
  if (cdsSelected in State) then begin<br>
    Sender.Canvas.Font.Style:=[<u></u>fsBold];<br>
    Sender.Canvas.Font.Color:=<u></u>clRed;<br>
  end<br>
  else begin<br>
    Sender.Canvas.Font.Style:=[];<br>
    Sender.Canvas.Font.Color:=<u></u>clBlack;<br>
  end;<br>
  rct:=Item.DisplayRect(drLabel)<u></u>;<br>
  Sender.Canvas.FillRect(rct); //paint background with default brush colour<br>
  Sender.Canvas.TextOut(rct.<u></u>Left, rct.Top, Item.Caption);<br>
end;<br>
<br>
end.<br>
<br>
--<br>
______________________________<u></u>_________________<br>
Lazarus mailing list<br>
<a href="mailto:Lazarus@lists.lazarus.freepascal.org" target="_blank">Lazarus@lists.lazarus.<u></u>freepascal.org</a><br>
<a href="http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus" target="_blank">http://lists.lazarus.<u></u>freepascal.org/mailman/<u></u>listinfo/lazarus</a><br>
</blockquote></div><br></div>