已经有很多朋友给出帮助,但是答案都不尽人意;http://www.delphibbs.com/delphibbs/DispQ.asp?LID=2960059希望大家提供经验

解决方案 »

  1.   

    重载DBGrid的DrawCell方法,把第1个位置没显示任何东西的列用来显示行数!
      

  2.   

    http://www.delphibbs.com/delphibbs/DispQ.asp?LID=2960059
      

  3.   

    为什么我的电脑上不了大富翁?说无法创建Application对象。
      

  4.   

    楼主试试这个.....~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    怎样在DbGrid的左边,实现像EXCEL那样的自动编号?这些编号与表无关
    unit Unit1;interfaceuses
     Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
     Grids, DBGrids, StdCtrls, Buttons, Db, DBTables, ExtCtrls, jpeg;
    const ROWCNT=20;type
        tmygrid=class(tdbgrid)
        protected
          procedure Paint;override;
          procedure DrawCell(ACol:Integer;ARow:Integer;ARect:TRect;AState:TGridDrawState);override;
        public
          constructor create(AOwner:TComponent);override;
          destructor  destroy;override;
        end; TForm1 = class(TForm)
       BitBtn1: TBitBtn;
       DataSource1: TDataSource;
       Table1: TTable;
       procedure BitBtn1Click(Sender: TObject);
     private
       { Private declarations }
     public
       { Public declarations }
     end;var
     Form1: TForm1;
     mygrid:tmygrid;
    implementation{$R *.DFM}    {tmygrid}
        constructor tmygrid.create(AOwner:TComponent);
        begin
           inherited create(Owner);
           RowCount:=ROWCNT;
        end;    destructor tmygrid.destroy;
        begin
          inherited;
        end;    procedure tmygrid.Paint;
        begin
          RowCount:=ROWCNT;
          if dgIndicator in options then
             ColWidths[0]:=30;
          inherited;
        end;    procedure tmygrid.DrawCell(ACol:Integer;ARow:Integer;ARect:TRect;AState:TGridDrawState);
        begin
          inherited;
          if (ARow>=1) and (ACol=0) then
             Canvas.TextRect(ARect,ARect.Left,ARect.Top,IntToSTr(ARow));
       end;procedure TForm1.BitBtn1Click(Sender: TObject);
    begin
     mygrid:=tmygrid.create(Self);
     mygrid.parent:=self;
     mygrid.left:=0;
     mygrid.top:=0;
     mygrid.Height:=300;
     mygrid.DataSource:=DataSource1;
    end;end. 
      

  5.   

    你把dbgrid的第一列设置位ID,在数据集查询的时候用一个id字段来计算编号就可以啦
      

  6.   

    这是一个自定义组件中显示序号的方法你可以将DBGrid的源码修改一下用来显示序号其实用DBGrid一点都不灵活procedure RGrid.ShowRowNo;
    var i,iCount:Integer;begin
      if FixedCols<1 then Exit;//如果没有序号区则不用显示行号
      iCount:=1;
       for i:=FixedRows to RowCount-1 do
       begin
         Cells[0,i]:=IntToStr(iCount);
         iCount:=iCount+1;
       end;
    end;
      

  7.   

    http://dev.csdn.net/article/53/53443.shtm--(53439.shtm)
      

  8.   

    select rownum,a,b,c from table1
      

  9.   

    定义一个计算字段,类型是fkCalculated型的,放在第一列
    在DBGrid的OnDrawColumnCell事件中if Column.Index = 0 then
      with DBGrid1.Canvas do
        begin
          FillRect(Rect);
          TextOut(Rect.Left+2, Rect.Top+2, IntToStr(DBGrid1.DataSource.DataSet.RecNo));
        end;
      

  10.   

    用stringgrid代替dbgrid也行!数据库中的值可以用循环赋给stringgrid!
      

  11.   

    如此挑剔,当然要用StringGrid
      

  12.   

    http://2days.blogchina.com/blog/article_61892.651925.html
    这个可行