怎样在dbgrid最左边加一列,显示序号!

simonqsm 2003-07-18 10:36:25
如标题!序号就是1,2,3,4根据记录数自动加1。
...全文
147 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
q1000 2003-07-19
  • 打赏
  • 举报
回复
最好是用
yesxwl() 的方法
cqwty 2003-07-19
  • 打赏
  • 举报
回复
上面的方法都可以的,自己想一下吧,
ihihonline 2003-07-19
  • 打赏
  • 举报
回复
No.1:
添加一个计算字段id

然后再table的onCalcFields事件里加
table.fieldbyname('id').asinteger:=table1.recno+1
就可以了

No.2:
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
if Column.Index = 5 then
with DBGrid1.Canvas do begin
FillRect(Rect);
TextOut(Rect.Left+2, Rect.Top+2, IntToStr(DBGrid1.DataSource.DataSet.RecNo));
end;
end;
yesxwl 2003-07-18
  • 打赏
  • 举报
回复
新增一个caculated字段id,integer;
在oncaculate事件中
with query1 do
filedbyname('id').asinteger:=recno
然后将id显示在grid最左边
sixgj 2003-07-18
  • 打赏
  • 举报
回复
你就在数据表内加上一 个+Autoicerement类型的字段,他会在记录增加后自动加1,然后在DBGrid里显示其在最左面就行了。

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧