dbgrideh颜色设置
(2010-06-30 10:30:59)
(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;