首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

统制stringgrid单元格的背景颜色

2012-11-09 
控制stringgrid单元格的背景颜色在SQL 2000 数据库中有一个字段(审核状态)。在stringgrid显示时,当审核状态

控制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; 

热点排行