简体   繁体   中英

Change color of DBGrid row

how change latest rec color dbgrid?

if (Sender as TDBGrid).DataSource.DataSet.RecNo = (Sender as TDBGrid)
  .DataSource.DataSet.RecordCount then
begin
  Canvas.Brush.Color := $00C66F71;
end;
(Sender as TDBGrid).DefaultDrawColumnCell(Rect, DataCol, Column, State);

Use OnDrawColumnCell property of TDbGrid

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if (Sender as TDBGrid).DataSource.DataSet.RecNo = (Sender as TDBGrid).DataSource.DataSet.RecordCount then
begin
  //change color of row    
  DBGrid1.Canvas.Brush.Color:=$00C66F71;
  DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

To change color of text use :

DBGrid1.Canvas.Font.Color:=clRed;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);

In your code

Canvas.Brush.Color:=$00C66F71;

is Canvas of the TForm , not Canvas of the TDbgrid

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM