Solved

Datagrid paging in Visual Basic

Posted on 2004-04-11
3
1,001 Views
Last Modified: 2013-12-25
Hello,

I want to know if there is any way to achieve datagrid paging in Visual
Basic... i.e., Next Page and Previous Page to navigate the data contained in
a datagrid.

I have searched the web, and can find plenty of articals about datagrid
paging in VB.NET and ASP.NET, but for the life of me I cannot find anything
relating to datagrid paging in Visual Basic 6.

Any help would be appreciated.

Thanks very much.

Note: The datagrid contains the data that is contained in a ADODC called datSalesReport.
0
Comment
Question by:glennston
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Accepted Solution

by:
MYLim earned 500 total points
ID: 10804271
Displaying

 large amounts of data, typically thousands of records, can present a number of obstacles. Firstly, navigation can be problematic in that the scrollbar becomes hyper-sensitive, jumping hundreds of records at the slightest touch. Secondly, overheads arise as a result of retrieving and populating forms with vast amounts of data.
The simple solution is to offer a filter on the data such as some chronological selection or an alphabetical filter such as surname grouping. However, such filtering opportunities may not exist, in which case, the only option is to display the data as a fixed number of records at a time, in a similar manner to which web searches return their results. To aid this approach, ADO offers three properties, PageSize, AbsolutePage and PageCount designed to control and manage the retrieval of large recordsets. The PageSize property set the number of records returned at a time and AbsolutePage determines which 'page' is returned, where the page is the group of records of size set by PageSize. Then the number of pages is simply calculated by ADO and accessed through the PageCount property.

Eg., if a recordset contains 500 records, and the PageSize is set to 50, the AbsolutePage can take the values 1 to 10, and the PageCount is 10. The example below, assumes a large recordset, rsExample, containing 1000's of records.

  Private Function DisplayPage(lngMaxRecs as Long, _
    lngPage as Long, rsExample as ADODB.Recordset)

      Dim intRow as Integer
      Dim lngHowManyRecs as Long
      Dim lngMaxPages as Long

      rsExample.PageSize = lngMaxRecs
      rsExample.AbsolutePage = lngPage

      lngHowManyRecs = 0
      lngMaxPages = rsExample.PageCount

      lblPage = "Page " & lngPage & " of " & lngMaxPages

      Do Until rsExample.EOF Or lngHowManyRecs >= lngMaxRecs

          ' intRow included to determine the row number
          ' for use in DataGrids
          intRow = rsExample.AbsolutePosition - _
            (rsExample.PageSize * (rsExample.AbsolutePage - 1))

          'populate form with data here

          rsExample.MoveNext
           
          lngHowManyRecs = lngHowManyRecs + 1

      Loop

  End Function
In the example function here, the page index and page size are passed as parameters to the function, controlling which set of data is displayed. This type of function could be called from a navigation control such as a series of cmdbuttons representing movefirst, moveprevious, movenext and movelast actions. The PageSize property, lngMaxRecs, could be set in a menu option or combobox etc. and the AbsolutePage property, lngPage would be set to 1, decremented, incremented or set to PageCount, respectively with respect to the 4 navigation controls above.
This method represents far greater efficiency over returning the entire recordset or holding a global recordset open and progressed throughout it. By contrast, the method above allows the recordset to be closed and the object killed after the function is executed. One point to note, controls must be in place to ensure a valid AbsolutePage parameter is passed within  the range of 1 to PageCount, ideally in the calling code where the recordset is created.

==============================================================
Try this after the recordeset.open command

rs.PageSize = 100 'the number of records in a "page"
rs.AbsolutePage = 1 ' show the first 100
set datagrid.DataSource = rs

The code should display only 100 records a time in your datagrid, to display the second 100 simply change rs.AbsolutePage to 2 and so on...
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question