辛巴德人设描写:在DBGRID里添加行序号

来源:百度文库 编辑:偶看新闻 时间:2024/07/05 13:51:28

在DBGRID里添加行序号

分类: Delphi 2008-10-08 08:50 297人阅读 评论(0) 收藏 举报
  1. //  1. create new blank field in dbgrid
  2. //  2. rename the title with 'No'
  3. //  3. put this code in OnDrawColumncell
  4. //  4. Now your Grid has a row number
  5. procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  6.   DataCol: Integer; Column: TColumn; State: TGridDrawState);
  7. begin
  8.   if DataSource1.DataSet.RecNo > 0 then
  9.   begin
  10.     if Column.Title.Caption = 'No' then
  11.       DBGrid1.Canvas.TextOut(Rect.Left + 2, Rect.Top, IntToStr(DataSource1.DataSet.RecNo));
  12.   end;
  13. end;
分享到: