有没有简单点ListView分页代码?
如题.谢谢!
[解决办法]
Option Explicit
Private db As New ADODB.Connection
Private MDBSystemPath As String
Private SQLConnectionString As String
Private Rest As New ADODB.Recordset
Private intPageCount As Integer
Private intPage As Integer
Private itemTemp As ListItem
Private Const PageSize As Integer = 5
Private I As Integer
Private Y As Integer
Private h As Integer
Private Sub commN_Click()
On Error GoTo handler
Me.ListView1.ListItems.Clear
intPage = intPage + 1
If intPage > intPageCount Then intPage = intPageCount ': Exit Sub
Rest.AbsolutePage = intPage
For I = 1 To PageSize
Set itemTemp = Me.ListView1.ListItems.Add
itemTemp.Text = Rest.Fields(0).Value
For Y = 1 To Rest.Fields.Count - 1
itemTemp.SubItems(Y) = Rest.Fields(Y)
Next
Rest.MoveNext
Next
handler:
If Err.Number = 3021 Then MsgBox "已达最后页! ", vbOKOnly, "提示 "
End Sub
Private Sub commP_Click()
Me.ListView1.ListItems.Clear
intPage = intPage - 1
If intPage <= 0 Then intPage = 1 ': Exit Sub
Rest.AbsolutePage = intPage
For I = 1 To PageSize
Set itemTemp = Me.ListView1.ListItems.Add
itemTemp.Text = Rest.Fields(0).Value
For Y = 1 To Rest.Fields.Count - 1
itemTemp.SubItems(Y) = Rest.Fields(Y)
Next
Rest.MoveNext
Next
End Sub
Private Sub Form_Load()
MDBSystemPath = App.Path & "\123.mdb "
'单机版
SQLConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Jet OLEDB:Database Password=7777777;Data Source= " & MDBSystemPath
'-------------------------------------------------------------------
'开始连接
db.Open SQLConnectionString
db.CursorLocation = adUseClient
Err.Clear
Rest.Open "Select * From abc order by a1 ", db, adOpenDynamic, adLockOptimistic
Rest.MoveLast
Rest.MoveFirst
intPage = 1
Rest.PageSize = PageSize
intPageCount = Rest.PageCount
If intPageCount < 1 Then Exit Sub
Y = Rest.Fields.Count
Me.ListView1.ColumnHeaders.Clear
For I = 0 To Y - 1
Me.ListView1.ColumnHeaders.Add , , Rest.Fields(I).Name
Next
Rest.AbsolutePage = intPage
For I = 1 To PageSize
Set itemTemp = Me.ListView1.ListItems.Add
itemTemp.Text = Rest.Fields(0).Value
For Y = 1 To Rest.Fields.Count - 1
itemTemp.SubItems(Y) = Rest.Fields(Y)
Next
Rest.MoveNext
Next
intPage = intPage + 1
End Sub
Private Sub Form_Unload(Cancel As Integer)
Rest.Close: Set Rest = Nothing
db.Close: Set db = Nothing
End Sub