拜托,实现这个与数据库没有关系,使DBGRid自己的事情,难怪没有人回答你,看看delphi的帮助

解决方案 »

  1.   

    你只要自己指定dbgrid的ondrawcolumn事件就可以了,确实与数据库没有关系
      

  2.   

    本人确实试了又试,Access和SQL的数据库就是不行,不信请自己试一下。
    但还是要请高手帮忙。
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
         if query1.recno mod 2<>0 then  dbgrid1.canvas.Brush.color:=$00eaeaea;
         dbgrid1.DefaultDrawcolumnCell(rect,datacol,column,state);
    end;
      

  3.   

    RecNo 只对 Paradox tables有效,其他的数据表一律都是-1不变
    看来你可以定义一个外部变量来代表了油标的移动了
      

  4.   

    用ADO Query连接数据就可以用RecNo啦!
      

  5.   

    还是没有人告诉我,在Acess.SQL数据库中怎样实现DBGrid表格控件中的色带问题。
    难道你们都不会吗?
      

  6.   

    下载一个组件就可以了:http://delphicoms.at.china.com//////////////////////////////////////////////////////////////////
    //               显示斑马线格式的 DBGrid 的组件                 //
    //             Program by PengFuZhang 2000.06.20                //
    //                 Email:[email protected]                    //
    //////////////////////////////////////////////////////////////////unit DBGridC;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Grids, DBGrids;type
      TDBGridC = class(TDBGrid)
      private
        { Private declarations }
        FC1:TColor;
        FC2:TColor;
      protected
        { Protected declarations }
        procedure DrawCell(Sender: TObject; const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
      public
        { Public declarations }
        Constructor Create(AOwner: TComponent); override;
        Procedure Scroll(Distance: Integer); override;
        Procedure About;
      published
        { Published declarations }
        Property C1:TColor Read FC1 Write FC1;
        Property C2:TColor Read FC2 Write FC2;
      end;procedure Register;implementationProcedure TDBGridC.About;
    Begin
         Application.MessageBox('PPanel 作者:彭富张 2000.03 Email:[email protected]','关于 PPanel',MB_OK+MB_ICONINFORMATION);
    End;Constructor TDBGridC.Create(AOwner: TComponent);
    Begin
         inherited Create(AOwner);
         C1:=$00E1FFFF;
         C2:=$00D3FED6;
         OnDrawColumnCell:=DrawCell;
    End;procedure TDBGridC.DrawCell(Sender: TObject; const Rect: TRect;
        DataCol: Integer; Column: TColumn; State: TGridDrawState);
    Var HPR:Integer;
    Begin
         If dgRowLines in Options Then
            HPR:=Rect.Bottom-Rect.Top+1
         Else
             HPR:=Rect.Bottom-Rect.Top;     If ((Rect.Top Div HPR) Mod 2)=0 Then
            Canvas.Brush.Color:=FC1
         Else
             Canvas.Brush.Color:=FC2;
         DefaultDrawColumnCell(Rect, DataCol, Column, State);
    End;procedure TDBGridC.Scroll(Distance: Integer);
    Begin
         inherited Scroll(Distance);
         Refresh;
    End;procedure Register;
    begin
      RegisterComponents('SLGIS', [TDBGridC]);
    end;end.
      

  7.   

    to:AP()
      感谢AP()同志的帮助,
      似乎代码也太长了吧!,是否不用组件也能实现能。
      

  8.   

    其实不困难,只要在判断行号时不使用数据库就可以了。以下是示例:
    procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    var
      iRow,iGridHeight : Integer;
    begin
      iGridHeight := Rect.Bottom - Rect.Top;
      iRow := (Rect.Top - iGridHeight ) div iGridHeight;
      if iRow mod 2 <> 0 then dbgrid1.canvas.Brush.color:=$00eaeaea;
      dbgrid1.DefaultDrawcolumnCell(rect,datacol,column,state);
    end;
      

  9.   

    to ameng007(阿门):
      感谢ameng007(阿门)的帮助,就让我试一试。
      

  10.   

    to ameng007(阿门):
      再次感谢您给我的帮助,
      经过调试,顺利通过你的方法,
      但程序运行起来显得不够稳定,能否有更好的办法,
      请广大的的delphi朋友加入进来。好吗!
      当然我会给ameng(阿门)加20分。