Title: Coloring selected Row in a dbgrid
Hi,
Many times the question is asked, but their is not much helpfull code. This code will do the trick.
Put the code in the onDrawColumnCell event and watch it happen
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (gdSelected in State) then
begin
DBGrid1.Canvas.Font.Color := clPurple;
DBGrid1.Canvas.Brush.Color := clLime;
DBGrid1.Canvas.FillRect(Rect);
DBGrid1.Canvas.TextOut(Rect.Left, Rect.Top,Column.Field.AsString);
end
else
begin
DBGrid1.Canvas.Font.Color := clBlue;
DBGrid1.Canvas.Brush.Color := clAqua;
DBGrid1.Canvas.FillRect(Rect);
DBGrid1.Canvas.TextOut(Rect.Left, Rect.Top,Column.Field.AsString);
end;
end;
steph