关于在VFP中用表格控件浏览数据表时的分页浏览

该博客介绍了如何在Visual FoxPro(VFP)环境中使用表格控件进行数据表的分页浏览。通过编写表单初始化代码和按钮点击事件处理,实现了打开、分页、上一页、下一页及关闭数据表的功能。具体实现涉及到记录源设置、临时文件创建、记录拷贝以及文件操作等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有一数据表ax.dbf,字段若干

有一表单,设置表格控件1个(grid1),按钮控件5个(功能分别为打开表、分页、上一页、下一页、关闭表)

假设所有文件都放在桌面上

要实现的功能是分页浏览

表单init代码

public rno,rc,pno,pc
SET SAFETY OFF
set path to C:/Documents and Settings/jwc/桌面/

打开表按钮click代码


select (select(1))
use ax.dbf
thisform.lockscreen=.t.
thisform.grid1.recordsourcetype=1
thisform.grid1.recordsource="ax"
thisform.lockscreen=.f.

分页按钮click代码

thisform.lockscreen=.t.
close databases
select (select(1))
use ax
goto top
rno=recno()
rc=reccount()
pno=1
pc=iif(rc/5-int(rc/5)>0,int(rc/5)+1,int(rc/5))
if file("axtemp.dbf")
if used("axtemp")
select axtemp
use
endif
delete file ax.temp
endif
copy to axtemp next 5
select (select(1))
use axtemp
thisform.grid1.recordsourcetype=1
thisform.grid1.recordsource="axtemp"
thisform.lockscreen=.f.

 上一页按钮click代码

if pno=1
messagebox("first")
else
thisform.lockscreen=.t.
close databases
select (select(1))
use ax
rc=reccount()
pc=iif(rc/5-int(rc/5)>0,int(rc/5)+1,int(rc/5))
pno=pno-1
rno=pno*5-4
if file("axtemp.dbf")
if used("axtemp")
select axtemp
use
endif
delete file ax.temp
endif
goto (rno)
copy to axtemp next 5
select (select(1))
use axtemp
thisform.grid1.recordsourcetype=1
thisform.grid1.recordsource="axtemp"
thisform.lockscreen=.f.
endif

下一页按钮click代码

if pno=pc
messagebox("last")
else
thisform.lockscreen=.t.
close databases
select (select(1))
use ax
rc=reccount()
pc=iif(rc/5-int(rc/5)>0,int(rc/5)+1,int(rc/5))
pno=pno+1
rno=pno*5-4
if file("axtemp.dbf")
if used("axtemp")
select axtemp
use
endif
delete file ax.temp
endif
goto (rno)
if rc-rno<5
copy to axtemp next (rc-rno)
else
copy to axtemp next 5
endif
select (select(1))
use axtemp
thisform.grid1.recordsourcetype=1
thisform.grid1.recordsource="axtemp"
thisform.lockscreen=.f.
endif

关闭表按钮click代码

close databases

完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值