控制stringgrid单元格的背景颜色
在SQL 2000 数据库中有一个字段(审核状态)。在stringgrid显示时,当审核状态为‘未审核’是为红色,当审核状态为‘已审核’是为绿色。。。
如果有代码请贴出代码。。谢谢!
在线求高手。。。急。急 急 急
[解决办法]
在TForm1.StringGrid1DrawCell中写:
- Delphi(Pascal) code
if StringGrid1.Cells[ACol,ARow]='未审核' then StringGrid1.Canvas.Brush.Color :=clRedelse if StringGrid1.Cells[ACol,ARow]='已审核' then StringGrid1.Canvas.Brush.Color :=clGreen;
[解决办法]
- Delphi(Pascal) code
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);begin with TStringGrid(Sender) do begin if ACol=5 then {5表示"审核"这一列;如果要整行变色,就去掉这一句} begin if Cells[ARow,ACol]='未审核' then {ACol->5} Canvas.Brush.Color:=clRed else Canvas.Brush.Color:=clGreen; Canvas.FillRect(Rect); Canvas.TextOut(Rect.Left+2,Rect.Top+2,Cells[ACol,ARow]); end; end;end;