当前位置: 代码迷 >> VB Dotnet >> 关于vb.net+access,中datagridview实现数据分页,网上给出个类,可是在程序中不能成功实现分页
  详细解决方案

关于vb.net+access,中datagridview实现数据分页,网上给出个类,可是在程序中不能成功实现分页

热度:171   发布时间:2016-04-25 02:11:17.0
求助关于vb.net+access,中datagridview实现数据分页,网上给出个类,可是在程序中不能成功实现分页,请指教
分页类代码
Public Class ClsDataGridViewPage
    Private _RowsPerPage As Integer '每页记录数
    Private _TotalPage As Integer '总页数
    Private _curPage As Integer = 0 '当前页数
    Private _DataGridView As Windows.Forms.DataGridView '要分页的DataGridView
    Private _dv As DataView '与需要分页显示的的DataView

    Public Property RowsPerPage() As Integer '获取与设置每页记录数
        Get
            Return _RowsPerPage
        End Get
        Set(ByVal value As Integer)
            _RowsPerPage = value
        End Set
    End Property

    '获取总页数
    Public ReadOnly Property TotalPage() As Integer
        Get
            Return _TotalPage
        End Get
    End Property

    '获取与设置当前页数
    Public Property curPage() As Integer
        Get
            Return _curPage
        End Get
        Set(ByVal value As Integer)
            _curPage = value
        End Set
    End Property

    '设置需要分页的SetDataGridView
    Public WriteOnly Property SetDataGridView()
        Set(ByVal value As Object)
            _DataGridView = value
        End Set
    End Property

    '设置需要分页显示的的DataView
    Public WriteOnly Property SetDataView()
        Set(ByVal value As Object)
            _dv = value
        End Set
    End Property

    Public Sub New()

    End Sub

    '重载NEW函数,在构造时就可以对成员赋值
    Public Sub New(ByVal datagridview As Windows.Forms.DataGridView, ByVal dv As DataView, ByVal RowsPerPage As Integer)
        _DataGridView = datagridview
        _dv = dv
        _RowsPerPage = RowsPerPage
    End Sub

    '开始分页啦
    Public Sub Paging()
        '首先判断DataView中的记录数是否足够形成多页,
        '如果不能,那么就只有一页,且DataGridView需要显示的记录等同于“最后一页”的记录
        If _dv.Count <= _RowsPerPage Then
            _TotalPage = 1
            GoLastPage()
            Exit Sub
        End If

        '可以分为多页的话就要计算总的页数咯,然后DataGridView显示第一页
        If _dv.Count Mod _RowsPerPage = 0 Then
            _TotalPage = Int(_dv.Count / _RowsPerPage)
        Else
            _TotalPage = Int(_dv.Count / _RowsPerPage) + 1
        End If
        GoFirstPage()
    End Sub

    '到第一页
    Public Sub GoFirstPage()
        '如果只有一页,那么显示的记录等同于“最后一页”的记录
        If _TotalPage = 1 Then
            GoLastPage()
            Exit Sub
        End If
        '如果有多页,就到第“1”页
        _curPage = 0
  相关解决方案