請教各位高手,如何將記錄號加到dbgrid 中?

來源:互聯網
上載者:User
請教各位高手,如何將記錄號加到dbgrid 中? Delphi / Windows SDK/API
http://www.delphi2007.net/DelphiDB/html/delphi_20061223091242150.html
下面我的dbgrid中顯示的代碼,如何將記錄號加到dbgrid   列中,謝謝了!  
  qq1:=tadoquery.Create(self);  
      qq1.Connection:=conn;  
      with   qq1   do  
      begin  
          close;  
          sql.Clear;  
          sql.Add('select   id,haoma   as   號碼,guishu   as   歸屬地,tongxunming   as   通訊公司   from   haoma   ');  
          open;  
      end;  
  datasource1.DataSet:=qq1;  
      dbgrid1.DataSource:=datasource1;

id   不就是記錄號麼

id   只是資料庫中的一個自動編號,不一定是從1開始,按依次加1的順序往下走的

{覆蓋DrawCell事件,顯示行序號   NO   }  
  procedure   TDBGridEh.DrawCell(ACol:Integer;ARow:Integer;ARect:TRect;AState:TGridDrawState);  
  var  
      i,DBRow,lLeft:integer;  
      iCol,iRow:integer;     //全域變數  
  begin  
      inherited;  
   
      {是否開啟顯示行號功能!}  
      if   fShowRecNo=True   then  
      begin  
          if   Assigned(DataLink)   and  
                  DataLink.Active   then   //沒有open  
          begin  
              if   (ARow>=1)   and  
                      (ACol=0)   then{行標題之內}  
              begin  
                  i                           :=   0;//位移值  
                  lLeft                   :=   0;//置中顯示  
                  DBRow                   :=   self.DataSource.DataSet.RecNo;//當前資料集所在的行標   rec   no  
                  if   DataSource.DataSet.RecNo=-1   then{新增選項組}  
                  begin  
                      DBRow   :=   DataSource.DataSet.RecordCount+1;//當前行標取記錄總數+1  
                  end;  
                  i             :=   DBRow   -   self.Row   ;//計算表格TopRow和資料集所在行的位移值(顯示實際資料集行號)  
                  lLeft     :=   (ARect.Right   -   ARect.Left)   div   2   -   Canvas.TextWidth(IntToSTr({DataLink.ActiveRecord}ARow+i))   div   2;//置中顯示  
                  Canvas.TextRect(ARect,ARect.Left+lLeft,ARect.Top,IntToSTr({DataLink.ActiveRecord}ARow+i));//輸出行號  
              end;  
          end;  
      end;  
  end;

 
      完整的有個控制項,使用非常簡單!  
       
      留下Email,我發給你.或加我QQ:67016879  
   
 

1、在DBGRID中增加一列,列名的抬頭比如說是'序號'  
  2、代碼:  
   
  procedure   TForm1.DBGrid1DrawColumnCell(Sender:   TObject;   const   Rect:   TRect;  
      DataCol:   Integer;   Column:   TColumn;   State:   TGridDrawState);  
  begin  
        if   DataSource1.DataSet.RecNo   >   0   then  
      begin  
          if   WideUpperCase(Column.Title.Caption)   =   '序號'   then  
              DBGrid1.Canvas.TextOut(Rect.Left   +   2,   Rect.Top,   IntToStr(DataSource1.DataSet.RecNo));  
      end;  
  end;  
 

好麻煩.

結貼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.