Recent

Author Topic: Selected row colour  (Read 871 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Selected row colour
« on: June 09, 2020, 06:02:49 pm »
How do I change the selected row colour?
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

wp

  • Hero Member
  • *****
  • Posts: 11916
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.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Selected row colour
« Reply #2 on: June 09, 2020, 06:56:22 pm »
Cheers!
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

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