在RowSelect属性为false时,DBGrid怎么实现给当前记录加底色?

解决方案 »

  1.   

    http://bbs.56kc.com/Browers.aspx?QID=2823
      

  2.   

    type
     TMyDBGrid=class(TDBGridEh);
    procedure Tcaxun_form.DBGridEh1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumnEh;
      State: TGridDrawState);
    begin
        with TMyDBGrid(Sender) do
     begin
       if DataLink.ActiveRecord=Row-1 then
       begin
         Canvas.Font.Color:=clWhite;
         Canvas.Brush.Color:=$00800040;
       end
       else
       begin
         Canvas.Brush.Color:=Color;
         Canvas.Font.Color:=Font.Color;
       end;
       DefaultDrawColumnCell(Rect,DataCol,Column,State);
     end;end;
      

  3.   

    默認的是籃色,如果換別的顏色在相關Draw事件中寫代碼,如樓上的那樣。
      

  4.   

    TO xuexi_110(不小心):
       兄台,你用的是TDBGridEh, 请问TDBGrid能不能实现?
      

  5.   

    procedure Tfrmmain.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumn;
      State: TGridDrawState);
    begin
     with DBGrid1 do
      with Canvas do begin
        if TMyGrid(DBGrid1).Row = MouseCoord(Rect.Left+1, Rect.Top+1).Y then
          Canvas.Brush.Color :=RGB(184,193,225);
        DefaultDrawColumnCell(Rect, DataCol, Column, State);
      end;
      if gdselected in state then exit;
     with (sender as tdbgrid).Canvas do
      begin
      pen.color:=$00ff0000;
      moveto(rect.left,rect.bottom);
      lineto(rect.right,rect.bottom);
      pen.Color:=clbtnface;
      moveto(rect.right,rect.Top);
      lineto(rect.right,rect.bottom);
      end;
    end;
      

  6.   

    TMyGrid(DBGrid1).Row 编译错误,哪里来的Row ?
      

  7.   

    请大家指教:
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
    //如果根据条件改变当前记录颜色的话,在此加入你的条件
      self.DBGrid1.Canvas.Font.Color:=clred;//设置当前记录字体颜色
      self.DBGrid1.Canvas.Brush.Color:=cl3Dlight;//设置当前记录背景颜色
      self.DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
    end;
      

  8.   

    用ehlib 就可以轻松实现了!
      

  9.   

    还没搞定给你一个dbgrid隔行显示不同的颜色的例子,你要相同得底色就把两个颜色设为相同得就可以了
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
    var Row,Col:Integer;
    begin
      TDrawGrid(Sender).MouseToCell(Rect.Left,Rect.Top,Col,Row);
      if Row Mod 2=0 then TDBGrid(Sender).Canvas.Font.Color:=clRed;
      TDBGrid(Sender).DefaultDrawColumnCell(Rect,DataCol,Column,State);
    end;