CSDN博客

img crazycock

DBGrid中分行分列、单元格的颜色设置

发表于2004/10/27 11:00:00  2952人阅读

(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;
阅读全文
0 0

相关文章推荐

img
取 消
img