Board index » delphi » How changing color of a ListView row ?

How changing color of a ListView row ?

I am using CB5 last release.
How changing color of a ListView row ?

Sam

 

Re:How changing color of a ListView row ?


Quote
>Sam wrote:

> I am using CB5 last release.
> How changing color of a ListView row ?

A simple example which colours every other row in a ListView
(ListView1.OwnerDraw = false):

procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView; Item:
TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
begin
  if (Item.Index mod 2) = 0 then begin
    Sender.Canvas.Brush.Color := clGray;
    Sender.Canvas.Font.Color := clWhite
  end else begin
    Sender.Canvas.Brush.Color := clSilver;
    Sender.Canvas.Font.Color := clRed
  end
end;
________
Andreas
Delphi 5.01 Pro, NT4.0 Sp5
Direct replies mailto:p...@augsburg.netsurf.de

Re:How changing color of a ListView row ?


Thank you it works fine,
 but is it possible to change only the color of the font for one column and
not the complete row ?

Sam
"Andreas Pawlik" <no~j...@augsburg.netsurf.de> a crit dans le message news:
39A017CF.16B3E...@augsburg.netsurf.de...

Quote
> >Sam wrote:

> > I am using CB5 last release.
> > How changing color of a ListView row ?

> A simple example which colours every other row in a ListView
> (ListView1.OwnerDraw = false):

> procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView; Item:
> TListItem; State: TCustomDrawState; var DefaultDraw: Boolean);
> begin
>   if (Item.Index mod 2) = 0 then begin
>     Sender.Canvas.Brush.Color := clGray;
>     Sender.Canvas.Font.Color := clWhite
>   end else begin
>     Sender.Canvas.Brush.Color := clSilver;
>     Sender.Canvas.Font.Color := clRed
>   end
> end;
> ________
> Andreas
> Delphi 5.01 Pro, NT4.0 Sp5
> Direct replies mailto:p...@augsburg.netsurf.de

Re:How changing color of a ListView row ?


Quote
>Sam wrote:

> Thank you it works fine, but is it possible to change only the color  > of the font for one column and not the complete row ?

Add a handler for the OnCustomDrawSubitem event which gives you an
additional subitem index parameter. Note that this index is not zero
based, subitem 1 refers to the first subitem (= ListItem.Subitems[0]).
________
Andreas
Delphi 5.01 Pro, NT4.0 Sp5
Direct replies mailto:p...@augsburg.netsurf.de

Re:How changing color of a ListView row ?


Thank you very much for your help.

Sam
"Andreas Pawlik" <no~j...@augsburg.netsurf.de> a crit dans le message news:
39A0597F.4C0DB...@augsburg.netsurf.de...

Quote
> >Sam wrote:

> > Thank you it works fine, but is it possible to change only the color  >

of the font for one column and not the complete row ?
Quote

> Add a handler for the OnCustomDrawSubitem event which gives you an
> additional subitem index parameter. Note that this index is not zero
> based, subitem 1 refers to the first subitem (= ListItem.Subitems[0]).
> ________
> Andreas
> Delphi 5.01 Pro, NT4.0 Sp5
> Direct replies mailto:p...@augsburg.netsurf.de

Other Threads