在dbgrideh表格显示下表
   F_Bookcode       F_name       F_phone    F_type         F_num
    0001             aaa          123        种类1           12
    0001             aaa          193        种类2           13   
    0002             bbb          145        种类3           16
    0003             ccc          135        种类5           19
    0003             ddd          157        种类1           20请问大家怎么样才能在控件里把F_bookcode相同的画为一种颜色,然后下面的单显示为另一种颜色
比如上表中F_bookcode为0001的两条记录显示为红色,那么0002显示为蓝色,0003的两条记录显示为红色,依此类推

解决方案 »

  1.   

    //在DrawColumnCell添加代码procedure TFrmFindPersonal.DBGridEh1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumnEh;
      State: TGridDrawState);
    begin
      IF ADOQuery1.FieldByName('IsLeave').AsBoolean then
        begin
          DBGridEh1.Canvas.Font.Color:=clRed;
          //DBGridEh1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
          DBGridEh1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
        end
      else
        begin
          if ADOQuery1.FieldByName('ischk').AsBoolean then
            begin
              DBGridEh1.Canvas.Font.Color:=clBlue;
              DBGridEh1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
            end
          else
            begin
              DBGridEh1.Canvas.Font.Color:=clDefault;
              DBGridEh1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
            end
        end;
    end;
      

  2.   

    ron_xin(星雨) 的应该有问题吧,
      IF ADOQuery1.FieldByName('IsLeave').AsBoolean then 只是当前记录吧
      

  3.   

    ColumnCell事件里~~~没错的`~我就是这样用的`~