//oncustomdrawcell事件写 if ASelected then afont.Color:=clred; //选中的栏的字体设为红色 scheck:=ANode.Values[dxDBGrid1status.Index]; //dxdbgrid1status为某一个指定字段 if not VarIsNull(scheck) then if scheck = '1' then //这段为指定值的判定,如果为1把这一行定义为白颜色
下面的程序是我经常在开发时使用的的 供各位大虾参考: procedure Tresultshowfrm.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin with DBGrid1.Canvas do begin if datamodule1.adoq_sqdj.FieldByName('bgrq').AsDateTime=date() then begin brush.Color:=clRed; font.Color:=clWhite; end; DBGrid1.DefaultDrawDataCell(rect,column.Field,state); end; end;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState); begin with DBGrid1 do if datasource.dataset.fieldbyname('Flag_js').asboolean=true then begin Canvas.font.color:=clblue;//如果条件为真,则字体颜色为蓝色 DefaultDrawColumnCell(rect,datacol,column,state); end; end;
if ASelected then afont.Color:=clred; //选中的栏的字体设为红色
scheck:=ANode.Values[dxDBGrid1status.Index]; //dxdbgrid1status为某一个指定字段
if not VarIsNull(scheck) then
if scheck = '1' then //这段为指定值的判定,如果为1把这一行定义为白颜色
AColor := clWhite
else
acolor:=clInfoBk;
Dbgrid1.Canvas.font.color:=clGreen;
供各位大虾参考:
procedure Tresultshowfrm.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
with DBGrid1.Canvas do
begin
if datamodule1.adoq_sqdj.FieldByName('bgrq').AsDateTime=date() then
begin
brush.Color:=clRed;
font.Color:=clWhite;
end;
DBGrid1.DefaultDrawDataCell(rect,column.Field,state);
end;
end;
dbgird.Columns[i].Font.color:=clBackground;//蓝色
clgreen; //绿色
还有很多颜色,自己看看;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
with DBGrid1 do
if datasource.dataset.fieldbyname('Flag_js').asboolean=true then
begin
Canvas.font.color:=clblue;//如果条件为真,则字体颜色为蓝色
DefaultDrawColumnCell(rect,datacol,column,state);
end;
end;