
delphi程序 我要修改DBGridEh 网格里面字段的字体颜色。
票数增减这个字段为负时,这条数据的票数增减的字体显示为红色,为正时不变,是字体颜色,不是填充色。...
票数增减这个字段为负时,这条数据的票数增减的字体显示为红色,为正时不变,是字体颜色,不是填充色。
展开
展开全部
在表格的DBGridEh1DrawColumnCell 事件中
if Column.FieldName='IO1' then //按字段为IO1'的列,来显示单元格颜色
begin
if ClientDataSet1.FieldByName('IO1').Value=0 then
begin
// DBGridEh1.Canvas.Brush.Color:=clRed; //行底色变色
DBGridEh1.Canvas.font.Color:=clLime; //行字体变色
DBGridEh1.DefaultDrawColumnCell(Rect,DataCol,Column,state);
end;
if ClientDataSet1.FieldByName('IO1').Value=1 then
begin
// DBGridEh1.Canvas.Brush.Color:=clRed; //行底色变色
DBGridEh1.Canvas.font.Color:=clred; //行字体变色
DBGridEh1.DefaultDrawColumnCell(Rect,DataCol,Column,state);
end;
end;
if Column.FieldName='IO1' then //按字段为IO1'的列,来显示单元格颜色
begin
if ClientDataSet1.FieldByName('IO1').Value=0 then
begin
// DBGridEh1.Canvas.Brush.Color:=clRed; //行底色变色
DBGridEh1.Canvas.font.Color:=clLime; //行字体变色
DBGridEh1.DefaultDrawColumnCell(Rect,DataCol,Column,state);
end;
if ClientDataSet1.FieldByName('IO1').Value=1 then
begin
// DBGridEh1.Canvas.Brush.Color:=clRed; //行底色变色
DBGridEh1.Canvas.font.Color:=clred; //行字体变色
DBGridEh1.DefaultDrawColumnCell(Rect,DataCol,Column,state);
end;
end;
展开全部
我给个每行过一行改遍一个字体颜色代码,,希望可以帮助到你
procedure TForm1.dbgrd1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
row: Integer;
begin
row := dbgrd1.DataSource.DataSet.RecNo;
if (row mod 2) <> 0 then
dbgrd1.Canvas.Font.Color := clRed
else
dbgrd1.Canvas.Font.Color := clBtnFace;
dbgrd1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
DBGridEh中分行分列、单元格的颜色设置
(1)分行不同颜色设置;在DBGridEh1DrawColumnCell中写;
if ADOQuery1.RecNo mod 2=0 then
begin
DBGridEh1.Canvas.Font.Color := clRed;
DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end
else begin
DBGridEh1.Canvas.Font.Color := clGreen;
DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
(2)分行不同背景颜色设置;在DBGridEh1DrawColumnCell中写;
if ADOQuery1.RecNo mod 2=0 then
begin
DBGridEh1.Canvas.Brush.Color := clRed;
DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end
else begin
DBGridEh1.Canvas.Brush.Color := clGreen;
DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
(3)符合条件的单元格颜色或者背景颜色设置;在DBGridEh1DrawColumnCell中写;
if Column.FieldName='价格' then
begin
if ADOQuery1.FieldByName('价格').AsFloat<0 then
begin
DBGridEh1.Canvas.Font.Color := clRed;
DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
end;
(4)交叉设置列颜色
1、为DBGridEh的每列的Color属性设置值。
2、将DBGridEh的RowColorFlag设为false;
参考:
http://hi.baidu.com/beer_zh/item/44951ade18c9814bdcf9be72
(1)分行不同颜色设置;在DBGridEh1DrawColumnCell中写;
if ADOQuery1.RecNo mod 2=0 then
begin
DBGridEh1.Canvas.Font.Color := clRed;
DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end
else begin
DBGridEh1.Canvas.Font.Color := clGreen;
DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
(2)分行不同背景颜色设置;在DBGridEh1DrawColumnCell中写;
if ADOQuery1.RecNo mod 2=0 then
begin
DBGridEh1.Canvas.Brush.Color := clRed;
DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end
else begin
DBGridEh1.Canvas.Brush.Color := clGreen;
DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
(3)符合条件的单元格颜色或者背景颜色设置;在DBGridEh1DrawColumnCell中写;
if Column.FieldName='价格' then
begin
if ADOQuery1.FieldByName('价格').AsFloat<0 then
begin
DBGridEh1.Canvas.Font.Color := clRed;
DBGridEh1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
end;
(4)交叉设置列颜色
1、为DBGridEh的每列的Color属性设置值。
2、将DBGridEh的RowColorFlag设为false;
参考:
http://hi.baidu.com/beer_zh/item/44951ade18c9814bdcf9be72
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |