表T1中有字符型字段color,记录内容为blue,red,black...(10种左右)。求怎么能在DBGrid中显示相应的颜色而不是字符?(100分)

  • 主题发起人 主题发起人 abv
  • 开始时间 开始时间
A

abv

Unregistered / Unconfirmed
GUEST, unregistred user!
用的第三方控件cxGrid,数据库为Access。
 
OnDrawColumnCell事件里写代码(这是DBGrid的,假设:颜色字段名为Color,类型为数值型)
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if (Column.FieldName = 'Color') then
begin
TDBGrid(Sender).Canvas.Brush.Color:= Column.Field.AsInteger;
TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
end;
end;
//由于你的字段存的是是blue,red,black等字符,所以要这样转换一下:
if Column.Field.AsString='blue' then TDBGrid(Sender).Canvas.Brush.Color:= clblue
else if Column.Field.AsString='red' then TDBGrid(Sender).Canvas.Brush.Color:= clRed, 其它的就自已写吧........................
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部