Board index » delphi » Help with using color to highlight rows in DBGrid

Help with using color to highlight rows in DBGrid

I am trying to sort a table by a boolean field and then display the table
in a DBGrid using 2 colors to differentiate those records with a 'true'
value from those records with a 'false' value.  I haven't been able to
figure out how to process each record on the DBGrid and assign a color
based on this criteria.  Can you help me figure out how to do this?
Thanks.

Lee Reynolds

Please e-mail reply to :     l...@warren.med.harvard.edu

 

Re:Help with using color to highlight rows in DBGrid


Try something like the following.

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if Column.FieldName = 'ItemsTotal' then
    begin
    if OrdersItemsTotal.Value > 10000 then
      begin
        DBGrid1.Canvas.Font.Color := Edit1.Color;  { Font color }
        DBGrid1.Canvas.Brush.Color := Edit2.Color; { Cell color }
      end;
      DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
    end;
end;

--
Bill

(TeamB cannot answer questions received via email.)
(To contact me for any other reason remove nospam from my address)

Other Threads