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;
=================================================================我自己的==============================
procedure TfrmMain.UserShowDbgehDrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumnEh; State: TGridDrawState); begin //先判断是否是这列,提升效率,不是这列的就跳过了. if Column.FieldName = 'top_user_type' then begin //然后判断当前值是否符合要求. if frmClientDm.UserCds.FieldByName('top_user_type').AsString = '0' then begin with UserShowDbgeh do begin //改变颜色 Canvas.Font.Color := clRed; Canvas.Brush.Color := clYellow; //重绘单元格 DefaultDrawColumnCell(Rect, DataCol, Column, GridsEh.TGridDrawState(State)); end; end; end; end;
本文来自博客园,作者:del88,转载请注明原文链接:https://www.cnblogs.com/del88/p/4624016.html