Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coloring selected Row in a dbgrid

Database Programming

Coloring selected Row in a dbgrid

by  Svanhooft  Posted    (Edited  )
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 [Bigglasses]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top