Recent

Author Topic: How can I change brush color in DBGrid?  (Read 4276 times)

Milsa

  • Sr. Member
  • ****
  • Posts: 328
How can I change brush color in DBGrid?
« on: May 07, 2016, 05:48:46 pm »
This is my code from Delphi in DBGridDrawColumnCell (it works):
Code: Pascal  [Select][+][-]
  1. (Sender as TDBGrid).Canvas.Brush.Color := clGray;
But in Lazarus doesn't works.
I work with Lazarus 4.0, FPC 3.2.2, date 2025-05-03
This information is actual to: 3rd Aug 2025

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: How can I change brush color in DBGrid?
« Reply #1 on: May 07, 2016, 07:33:10 pm »
The event for changing canvas properties in descendants of TCustomGrid is OnPrepareCanvas:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.DBGrid1PrepareCanvas(sender: TObject; DataCol: Integer;
  2.   Column: TColumn; AState: TGridDrawState);
  3. begin
  4.   if odd(TDBGrid(Sender).DataSource.Dataset.RecNo) then    // NOTE: RecNo is not available for all dataset types!
  5.     TDBGrid(Sender).Canvas.Brush.Color := clSilver;
  6.   if DataCol = 0 then   // or: if Column.Index = 0 then
  7.     TDBGrid(Sender).Canvas.Font.Style := [fsBold];
  8. end;
« Last Edit: May 07, 2016, 07:36:21 pm by wp »

 

TinyPortal © 2005-2018