读取Access后Listview分页显示如何实现?(已解决)
本帖最后由 qq342252004 于 2012-2-4 17:27 编辑读取Access后Listview分页显示如何实现?效果请看图片,附件里有Access数据文件和源码,会的朋友请帮帮忙。 分页无非是自己控制行数,然后刷新 http://www.autoitx.com/forum.php?mod=redirect&goto=findpost&ptid=16591&pid=181148&fromuid=7644923 建议你读取ACCESS数据的时候采用分页,ACCESS读取是支持分页的。这样不用把数据全部读出来,然后得到分页数量等等,下页就变成了读取数据库下页! 分页无非是自己控制行数,然后刷新
netegg 发表于 2012-2-4 01:07 http://www.autoitx.com/images/common/back.gif
正是这个意思。
afan 发表于 2012-2-4 01:39 http://www.autoitx.com/images/common/back.gif
我要的效果是你这个例子,问题是读取Access的我不会变通啊。 本帖最后由 sdc7 于 2012-2-4 15:34 编辑
如果解决了就把标题 标上已解决谢谢`
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
Global $access="Data.mdb"
Global $password=""
$con=ObjCreate("adodb.connection")
$con.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&$access&";Jet Oledb:Database Password="&$password)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 200, 300)
$ListView1 = GUICtrlCreateListView("ID|001|002|003", 0, 0, 200, 250)
$s=read()
MsgBox(1,"当前有"&$s&"页","分页看到了吗,下一页的话 调用read传个页码!")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func read($page=0)
GUICtrlSendMsg($ListView1,$LVM_DELETEALLITEMS, 0, 0)
$rs=ObjCreate("adodb.recordset")
$rs.activeconnection=$con
$rs.open("select * from List",$con,1,1)
If Not $RS.eof And Not $RS.bof Then
$rs.pagesize=5;每页条数
if $page<1 then $page=1
if $page>$rs.pagecount then $page=$rs.pagecount
$rs.absolutepage=$page
for $i=1 to $rs.pagesize
if @error =1 Then ExitLoop
GUICtrlCreateListViewItem ($RS.Fields (0).value&"|"& $RS.Fields (1).value&"|"& $RS.Fields (2).value&"|"& $RS.Fields (3).value,$ListView1)
$rs.movenext
if $rs.eof then ExitLoop
next
$p=$rs.pagecount
$rs.close
EndIf
Return $p
EndFunc #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 谢谢大家帮忙,辛苦了。 最近学习数据库进来看看。 楼主很强大,又学习了 回帖收藏,
页:
[1]