找回密码
 加入
搜索
查看: 6981|回复: 11

[GUI管理] 读取Access后Listview分页显示如何实现?(已解决)

  [复制链接]
发表于 2012-2-4 00:50:41 | 显示全部楼层 |阅读模式
本帖最后由 qq342252004 于 2012-2-4 17:27 编辑

读取Access后Listview分页显示如何实现?效果请看图片,附件里有Access数据文件和源码,会的朋友请帮帮忙。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2012-2-4 01:07:57 | 显示全部楼层
分页无非是自己控制行数,然后刷新
发表于 2012-2-4 01:39:22 | 显示全部楼层
发表于 2012-2-4 10:12:19 | 显示全部楼层
建议你读取ACCESS数据的时候采用分页,ACCESS读取是支持分页的。这样不用把数据全部读出来,然后得到分页数量等等,下页就变成了读取数据库下页!
 楼主| 发表于 2012-2-4 14:39:14 | 显示全部楼层
分页无非是自己控制行数,然后刷新
netegg 发表于 2012-2-4 01:07

正是这个意思。
 楼主| 发表于 2012-2-4 14:54:27 | 显示全部楼层
afan 发表于 2012-2-4 01:39

我要的效果是你这个例子,问题是读取Access的我不会变通啊。
发表于 2012-2-4 15:33:35 | 显示全部楼层
本帖最后由 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

评分

参与人数 2金钱 +40 收起 理由
qq342252004 + 20 谢谢帮忙,辛苦了。
afan + 20

查看全部评分

发表于 2012-2-4 16:10:26 | 显示全部楼层
#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

评分

参与人数 2金钱 +45 收起 理由
qq342252004 + 20 谢谢帮忙,辛苦了。
afan + 25

查看全部评分

 楼主| 发表于 2012-2-4 17:26:31 | 显示全部楼层
谢谢大家帮忙,辛苦了。
发表于 2012-2-4 18:25:23 | 显示全部楼层
最近学习数据库进来看看。
发表于 2013-11-9 09:36:00 | 显示全部楼层
楼主很强大,又学习了
发表于 2016-4-30 23:33:38 | 显示全部楼层
回帖收藏,
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-18 13:38 , Processed in 0.088784 second(s), 30 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表