(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;
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;
博客介绍了DBGridEh控件的颜色设置方法,包括分行设置不同字体颜色、分行设置不同背景颜色,以及符合条件的单元格颜色或背景颜色设置,均在DBGridEh1DrawColumnCell中编写代码实现。
2755

被折叠的 条评论
为什么被折叠?



