0

I used default style "Amethyst Kamri" in application. And my DBgrid's selected row color change according to style. But i want to change selected row's border color and background color. I change font style using the answer of following question.

https://stackoverflow.com/a/9472000

Now i want to change color. How to do this?

Community
  • 1
  • 1
Ganpat
  • 768
  • 3
  • 15
  • 30

1 Answers1

1

You need first to inherit the TDBGrid from the Vcl.DBGrids.TDBGrid calss .And override the Paint procedure . Like this :

type
  TDBGrid = class(Vcl.DBGrids.TDBGrid)
  protected
    procedure Paint; override;
  end;

On the Paint procedure :

procedure TDBGrid.Paint;
var
  i, X, Y: Integer;
begin
  inherited;
  Y := RowHeights[0] + 1;
  X := Width;
  for i := 1 to Self.RowCount - 1 do
  begin
    Y := Y + RowHeights[i] + 1;
    Canvas.Brush.Color := clRed;
    Canvas.FillRect(Rect(0, Y, X, Y + 1));
  end;
end;

And this is the final result :

enter image description here

S.MAHDI
  • 1,022
  • 8
  • 15