Delphi DbGrid上色问题

DbGrid的OnDrawColumnCell事件
如你现在有一个ADOTable1,一个DbGrid1,假如你数据库里面的列名分别是(序号,名字,年龄),你要将年龄为23的格填充背景色为黑色,字体颜色改为白色,代码如下:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if adoTable1.FieldByName('年龄').AsString = '23' then
begin
DBGrid1.Canvas.Brush.Color:=clBlack;
dbgrid1.Canvas.Font.Color := clWhite;
end;
if DataCol = 3 then
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;

你可能感兴趣的:(Delphi)