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

StringGrid单元格填充颜色解决思路

2012-02-25 
StringGrid单元格填充颜色我想编写:StringGrid1控件第五列的值如果等于True,则把该值所在的行的颜色填充为

StringGrid单元格填充颜色
我想编写:

StringGrid1控件第五列的值如果等于True,则把该值所在的行的颜色填充为黄色,
如果StringGrid1控件第五列的值等于False,则把该值所在的行的颜色填充为灰色。

请高手多指点!

[解决办法]
抛砖引玉

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
var Value : string;
begin
with TStringGrid(Sender) do
begin
Value := Cells[ACol,ARow];
if UpperCase(Cells[4,ARow])= 'TRUE ' then
Canvas.Brush.Color := clYellow
else if UpperCase(Cells[4,ARow])= 'FALSE ' then
Canvas.Brush.Color := clGray
else Canvas.Brush.Color := clWhite;
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left,Rect.Top,Value);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
StringGrid1.Cells[4,1] := 'True ';
StringGrid1.Cells[4,3] := 'False ';
StringGrid1.Refresh;
end;

热点排行