Recent

Author Topic: Selected row colour  (Read 408 times)

pcurtis

  • Sr. Member
  • ****
  • Posts: 377
Selected row colour
« on: June 09, 2020, 06:02:49 pm »
How do I change the selected row colour?
Windows 10 / Linux Mint 20
Laz 2.10.0
FPC 3.2.0

wp

  • Hero Member
  • *****
  • Posts: 7933
Re: Selected row colour
« Reply #1 on: June 09, 2020, 06:45:04 pm »
Selected Row of a TDBGrid?

Use the OnPrepareCanvas event and try this code:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.DBGrid1PrepareCanvas(sender: TObject; DataCol: Integer;
  2.   Column: TColumn; AState: TGridDrawState);
  3. begin
  4.   if ([gdSelected, gdFocused] * AState <> []) then begin
  5.     if (DBGrid1.SelectedColumn = Column) then begin
  6.       DBGrid1.Canvas.Brush.Color := clRed;
  7.       DBGrid1.Canvas.Font.Color := clWhite;
  8.     end else
  9.     begin
  10.       DBGrid1.Canvas.Brush.Color := RgbToColor(255, 128, 128);
  11.       DBGrid1.Canvas.Font.Color := clBlack;
  12.     end;
  13.   end;
  14. end;

This is for row-select mode, but you certainly can adapt it to normal single-cell mode easily.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

pcurtis

  • Sr. Member
  • ****
  • Posts: 377
Re: Selected row colour
« Reply #2 on: June 09, 2020, 06:56:22 pm »
Cheers!
Windows 10 / Linux Mint 20
Laz 2.10.0
FPC 3.2.0

Focus77

  • New Member
  • *
  • Posts: 25
Re: Selected row colour
« Reply #3 on: June 11, 2020, 09:00:03 pm »
Hello !

But did you notice that if  dgRowselect=True

The left and the right buttons don't work ?  :(
My goal is to make a web Application
using HTTPServer

 

TinyPortal © 2005-2018