在DrawColumnCell事件写代码即可. 这个例子,你参考一下: var clBack : TColor; begin clBack := (Sender As TDbGrid).Canvas.Brush.Color; With Sender As TDbGrid do begin if (gdSelected) in State then begin (Sender As TDbGrid).Canvas.Brush.Color := clblue; end else begin Canvas.Brush.Color := clBack; Canvas.Font.Color := clblack; end; if (Sender As TDbGrid).DataSource.DataSet.FieldByName('jwxh').AsInteger = 1 then //封锁揭示 begin Canvas.Brush.Color := clWhite; Canvas.Font.Color := clBlue; end else if (Sender As TDbGrid).DataSource.DataSet.FieldByName('jwxh').AsInteger = 2 then //特殊揭示 begin Canvas.Brush.Color := clWhite; Canvas.Font.Color := clGreen; end else if (Sender As TDbGrid).DataSource.DataSet.FieldByName('jwxh').AsInteger = 3 then //车站限速 begin Canvas.Brush.Color := clWhite; Canvas.Font.Color := clTeal; end else if (Sender As TDbGrid).DataSource.DataSet.FieldByName('jwxh').AsInteger = 4 then //侧线限速 begin Canvas.Brush.Color := clWhite; Canvas.Font.Color := clMoneyGreen; end else if (Sender As TDbGrid).DataSource.DataSet.FieldByName('jwxh').AsInteger = 5 then //信号停用 begin Canvas.Brush.Color := clWhite; Canvas.Font.Color := clFuchsia; end else if (Sender As TDbGrid).DataSource.DataSet.FieldByName('jwxh').AsInteger = 6 then //绿色凭证 begin Canvas.Brush.Color := clWhite; Canvas.Font.Color := clLime; end else if (Sender As TDbGrid).DataSource.DataSet.FieldByName('jwxh').AsInteger = 7 then //特定引导 begin Canvas.Brush.Color := clWhite; Canvas.Font.Color := clAqua; end; end; (Sender As TDbGrid).DefaultDrawColumnCell(Rect, DataCol, Column, State);
这个例子,你参考一下:
var
clBack : TColor;
begin
clBack := (Sender As TDbGrid).Canvas.Brush.Color;
With Sender As TDbGrid do
begin
if (gdSelected) in State then
begin
(Sender As TDbGrid).Canvas.Brush.Color := clblue;
end
else
begin
Canvas.Brush.Color := clBack;
Canvas.Font.Color := clblack;
end; if (Sender As TDbGrid).DataSource.DataSet.FieldByName('jwxh').AsInteger = 1 then //封锁揭示
begin
Canvas.Brush.Color := clWhite;
Canvas.Font.Color := clBlue;
end
else
if (Sender As TDbGrid).DataSource.DataSet.FieldByName('jwxh').AsInteger = 2 then //特殊揭示
begin
Canvas.Brush.Color := clWhite;
Canvas.Font.Color := clGreen;
end
else
if (Sender As TDbGrid).DataSource.DataSet.FieldByName('jwxh').AsInteger = 3 then //车站限速
begin
Canvas.Brush.Color := clWhite;
Canvas.Font.Color := clTeal;
end
else
if (Sender As TDbGrid).DataSource.DataSet.FieldByName('jwxh').AsInteger = 4 then //侧线限速
begin
Canvas.Brush.Color := clWhite;
Canvas.Font.Color := clMoneyGreen;
end
else
if (Sender As TDbGrid).DataSource.DataSet.FieldByName('jwxh').AsInteger = 5 then //信号停用
begin
Canvas.Brush.Color := clWhite;
Canvas.Font.Color := clFuchsia;
end
else
if (Sender As TDbGrid).DataSource.DataSet.FieldByName('jwxh').AsInteger = 6 then //绿色凭证
begin
Canvas.Brush.Color := clWhite;
Canvas.Font.Color := clLime;
end
else
if (Sender As TDbGrid).DataSource.DataSet.FieldByName('jwxh').AsInteger = 7 then //特定引导
begin
Canvas.Brush.Color := clWhite;
Canvas.Font.Color := clAqua;
end; end;
(Sender As TDbGrid).DefaultDrawColumnCell(Rect, DataCol, Column, State);