TStringGrid与TDBGrid不尽相同.
procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
with StringGrid1.Canvas do
begin
if ARow=StringGrid1.Row then //判断是否为当前行,也可以任意制定行
begin
Brush.Color:=clYellow;
Font.Color:=clRed;
Font.Style:=[fsBold,fsItalic];
end
else
begin
Brush.Color:=clWhite;
Font.Color:=clBlack;
end;
FillRect(Rect);
TextOut(Rect.Left+2,Rect.Top+3,StringGrid1.Cells[ACol,ARow]);
end;
end;
procedure TForm1.StringGrid1Click(Sender: TObject);
begin
StringGrid1.Repaint; //由于DrawCell事件每次只画一个(我的试验结果),在此强制刷新
end;