用label可以显示出分页的内容,但怎么把分页的内容显示在MSHFlexGrid上呢?

解决方案 »

  1.   

    指定记录集每页显示的记录数,每次从中取出一页的内容显示在MSHFlexGrid上。
      

  2.   

    同意qjqmoney(天涯过客)的做法。
      

  3.   

    给你一个函数:
    '---------分页显示过程---------------------
    Public Function EveryRowDisplay(ByRef MSHFGrd As MSHFlexGrid, ByRef sql As String, ByRef formatStr As String, ByVal rowSum As Integer, ByVal colSum As Integer) As String
    '''''''''''''''''''返回数据总页数Dim n As Integer
    Opendb
    rs.CursorLocation = adUseClient
    Debug.Print sql
    rs.Open sql, Cn, 1, 2
    If Not rs.EOF Then
        Dim pageSum As Integer '''''取总页数
        Dim Rcounts As Integer ''''当数据总数小于设定行时取得显示数据的最大行
        Dim RsP As Integer '''''获得当前纪录的位置    rs.PageSize = rowSum
        Rcounts = rs.RecordCount
        
        
        If (Rcounts / rowSum) - 1 > 0 Then
            pageSum = ((Rcounts - 1) \ rowSum) + 1
        Else
            pageSum = 1
        End If
        
        
        If StartP > rs.PageCount Then
            StartP = rs.PageCount
        End If
        
        If StartP < 1 Then
            StartP = 1
        End If
        
        rs.AbsolutePage = StartP
        MSHFGrd .Clear
        With MSHFGrd 
            .formatString = formatStr
            .Cols = rs.Fields.Count
            .Rows = rowSum + 1
            For i = 1 To rowSum
                For j = 0 To colSum - 1
                .TextMatrix(i, j) = rs.Fields(j) & ""
                Next
                rs.MoveNext
                If rs.EOF Then      '判断记录是否了到最后一条
                   GoTo DSPend
                End If
            Next
        End With
    Else
        MSHFGrd .Clear
        MSHFGrd .formatString = formatStr
    End IfDSPend:
        rs.Close
        Cn.Close
        Set rs = Nothing
        Set Cn = Nothing
        If pageSum = 0 Then
            EveryRowDisplay= 0 & "/" & pageSum
        Else
            EveryRowDisplay= StartP & "/" & pageSum    End If
    End Function