求助:设置DBGRID中某一列的颜色(50分)

  • 主题发起人 主题发起人 yeli
  • 开始时间 开始时间
Y

yeli

Unregistered / Unconfirmed
GUEST, unregistred user!
我在OnDrawColumnCell中设
DBgrid1.canvas.color := StringtoColor(query1.fieldvalues['色样']) ;
DBGrid1.DefaultDrawColumnCell(Rect,Datacol,Column,State);
却显示整行的颜色,我想只把颜色显示在字段'色样'中,应该怎么做啊?在线等候
 
procedure TForm1.DBGridDrawColumnCell(Sender: TObject;
const Rect: TRect;
DataCol: Integer;
Column: TColumnEh;
State: TGridDrawState);
begin
if (TCustomADODataSet(AdoQuery1).Recno mod 2)=0 then
//记录号是双数
begin
(sender as TDBGridEh).Canvas.Font.Color:=clblack;
(sender as TDBGridEh).Canvas.Brush.color:=$00C5EBE7
end
else
begin
(sender as TDBGrid).Canvas.Font.Color:=clblack;
(sender as TDBGrid).Canvas.Brush.color:=$00ABECEF
end;
(sender as TDBGrid).DefaultDrawColumnCell(Rect,DataCol,Column,State);
end;
 
Column.Font.Color := clRed;
试试,这是设置某一列的字体的,没问题的!
祝你好运!!!
 
if DataCol=1 then
begin
DBGrid1.Canvas.Font.Color:=clblack;
DBGrid1.Canvas.Brush.color:=$00C5EBE7;
end;
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
 
偏离原意了
 
to Gingerzy:理解错了
to lty_ty :该怎么设呢?
to delphiland,我试过你的方法,不行的
if DataCol=1 then
 //有错
begin
DBGrid1.Canvas.Font.Color:=clblack;
DBGrid1.Canvas.Brush.color:=$00C5EBE7;
end;
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
 
if DataCol=1 then
//字段'色样'在DBGrid中的列序号(从0开始)
begin
DBGrid1.Canvas.Font.Color:=clblack;
DBGrid1.Canvas.Brush.color:=StringtoColor(Query1.fieldvalues['色样']) ;
end;
DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
 
if DataCol=1 then
换成
if DBGrid1.Columns[DataCol].FieldName:='色样' then
更好。
 
to delphiland:谢谢。成功了,我刚才没有判断QUERY语句,才导致错误
 
接受答案了.
 
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect;
DataCol: Integer;
Column: TColumn;
State: TGridDrawState);
begin
if column.FieldName='色样' then
//////////////////////////
// ..................
end;
 
后退
顶部