#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
Global $access="Data.mdb"
Global $password=""
Local $dqyc
Local $Label,$Combo
$conn=ObjCreate("adodb.connection")
$conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&$access&";Jet Oledb:Database Password="&$password)
$rs=ObjCreate("adodb.recordset")
$rs.open("select * from List",$conn,1,1)
$rs.pagesize=6 ;每页容纳的数据条数
#Region ### START Koda GUI section ### Form=
GUICreate("Listview分页显示", 400, 450)
$ListView1 = GUICtrlCreateListView("ID|001|002|003", 5, 5, 390, 380, -1, BitOR($WS_EX_CLIENTEDGE, $LVS_EX_FULLROWSELECT, $LVS_REPORT))
read(1)
$Button1 = GUICtrlCreateButton("<", 110, 400, 30, 22)
$Button2 = GUICtrlCreateButton(">", 190, 400, 30, 22)
$Label = GUICtrlCreateLabel('1', 143, 405, 18, 17, 0x0002)
GUICtrlCreateLabel('/' & $rs.pagecount, 162, 405, 23, 17)
$Button3 = GUICtrlCreateButton("返回首页", 30, 400, 80, 22)
$Button4 = GUICtrlCreateButton("跳至尾页", 220, 400, 80, 22)
$Combo = GUICtrlCreateCombo('', 305, 402, 60, 22)
$Combodata = ''
For $i = 1 To $rs.pagecount
$Combodata &= '第' & $i & '页|'
Next
GUICtrlSetData($Combo, $Combodata, '第1页')
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
$rs.close
$conn.close
Exit
Case $Button1 ;上一页
read($dqyc - 1)
Case $Button2 ;下一页
read($dqyc + 1)
Case $Button3 ;首页
read(1)
Case $Button4 ;尾页
read($rs.pagecount)
Case $Combo ;下拉选择页次
read(StringRegExpReplace(GUICtrlRead($Combo), '[^\d]', ''))
EndSwitch
WEnd
Func read($page)
$page = Int($page)
If $page < 0 Or $page > $rs.pagecount Then $page = 1
GUICtrlSetData($Label, $page)
GUICtrlSetData($Combo, '第' & $page & '页')
$dqyc = $page
$rs.AbsolutePage = $page
$mypagesize = $rs.pagesize
GUICtrlSendMsg($ListView1,$LVM_DELETEALLITEMS, 0, 0)
while (Not $RS.eof And $mypagesize > 0)
if @error =1 Then ExitLoop
GUICtrlCreateListViewItem ($RS.Fields (0).value&"|"& $RS.Fields (1).value&"|"& $RS.Fields (2).value&"|"& $RS.Fields (3).value,$ListView1)
$mypagesize -= 1
$rs.movenext
WEnd
EndFunc