J
jimshu
Unregistered / Unconfirmed
GUEST, unregistred user!
我需要在DBGrid中显示Boolean值,源码如下:
procedure Form1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if gdSelected in State then Exit;
// 两行之间用不同颜色分隔
if (Sender as TDBGrid).DataSource.DataSet.RecNo mod 2=0 then
(Sender as TDBGrid).Canvas.Brush.Color:=clInfoBk
else
(Sender as TDBGrid).Canvas.Brush.Color:=RGB(191,255,223);
//显示boolean值
if Column.Field.DataType=ftBoolean then
if Column.Field.Value=True then
Canvas.Textout(Rect.left+4,Rect.top+4,'V')
else Canvas.Textout(Rect.left+4,Rect.top+4,'X'); //*****!!!
(Sender as TDBGrid).DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
在“//*****!!!”标记的那两行虽然执行了,却没有效果。
以上在Delphi7环境中。我记得以前用Delphi5就可以写在OnDrawDataCell事件就没问题,可是Delphi7已经废止了OnDrawDataCell,只可以使用OnDrawColumnCell 。
同样的,我在DBGrid中画图也不能显示我需要的结果。
procedure Form1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if gdSelected in State then Exit;
// 两行之间用不同颜色分隔
if (Sender as TDBGrid).DataSource.DataSet.RecNo mod 2=0 then
(Sender as TDBGrid).Canvas.Brush.Color:=clInfoBk
else
(Sender as TDBGrid).Canvas.Brush.Color:=RGB(191,255,223);
//显示boolean值
if Column.Field.DataType=ftBoolean then
if Column.Field.Value=True then
Canvas.Textout(Rect.left+4,Rect.top+4,'V')
else Canvas.Textout(Rect.left+4,Rect.top+4,'X'); //*****!!!
(Sender as TDBGrid).DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
在“//*****!!!”标记的那两行虽然执行了,却没有效果。
以上在Delphi7环境中。我记得以前用Delphi5就可以写在OnDrawDataCell事件就没问题,可是Delphi7已经废止了OnDrawDataCell,只可以使用OnDrawColumnCell 。
同样的,我在DBGrid中画图也不能显示我需要的结果。