Board index » delphi » Colors in DBgrid Cells

Colors in DBgrid Cells

Hi,

I read some information from a database into a DBgrid. Now i want to
color some of the cells (not all). Can someone give me a sample how to
do this?

Greetings from the Netherlands,

Robert Copier

 

Re:Colors in DBgrid Cells


Robert Copier <rcop...@monicom.nl.NoSpam> ???? a ?t
<34396DF5.5...@monicom.nl.NoSpam>...

Quote
> Hi,

> I read some information from a database into a DBgrid. Now i want to
> color some of the cells (not all). Can someone give me a sample how to
> do this?

You must write your own handler for DBGrid.DrawDataCell and set
DefaultDrawing property to false.
For sample:

(* here DictGrid is DBGrid component *)

procedure TDictionary.DictGridDrawDataCell(Sender: TObject;
  const Rect: TRect; Field: TField; State: TGridDrawState);
begin
 with DictGrid.Canvas do
 begin
   if not (gdSelected in state) then
     begin
      Brush.Color := clWhite;
      Font.Color := clBlue;
     end
   else
     begin
      Brush.Color := clYelloW;
      Font.Color := clBlack;
     end;
  DictGrid.DefaultDrawDataCell(Rect, Field, State);
 end;
end;

Other Threads