Click here to Skip to main content
15,397,729 members
Articles / Desktop Programming / Windows Forms
Posted 17 Apr 2009


38 bookmarked

Data Pagination in DataGridView. Bounded Mode

Rate me:
Please Sign up or sign in to vote.
4.67/5 (9 votes)
17 Apr 2009CPOL2 min read
How to use DataGridView pagination in bounded mode


Most of the time, I use .NET Framework 2.0 and its Windows Forms API. One of the most widely used controls is a DataGridView. But as it has already been said many times it leaks of data paging. There are a lot of articles all over the Internet dealing with paging in a DataGridView. Most of them propose a use of DataGridView virtual mode. I will try to implement it in a bounded mode.


I was working with web-services that suppose a lot of work with XML data and once had to implement embedded .NET control for Internet Explorer that was supposed to show to a user large lists of data in DataGridView controls. Moreover, users should be able to filter and sort the data shown. There were no problems with lists that had 100-300 rows. But if a list had something like 10000 - 20000 rows, then it is another situation. Using of the DataGridView virtual mode did not resolve a problem with filtering and sorting, so one of the solutions was to implement caching in the bounded mode.

Using the Code

The code is just an idea. So you should implement your own data access layer. It means web-services or access to a local database. You could implement a functionality of IBindedListView interface that I missed. I've used XML request as an argument of page provider but you can implement your own realization that will meet your needs.

Underlying Layer

At this level, we will define an entity to be shown in our DataGridView. Let’s choose a company list with the following structure:

Create table Organizations 
ID int,
StateAbbr char(2),
StateName char(50),
OrganizationName char(150),
AgencyName char(150),
LocalPhone char(20)

A corresponding XML element will look like:

<organization id="1" statename="Alaska" stateabbr="AK" />

And a corresponding entity will look like:

    public class Organization
        private int mID;
        private string mStateAbbr = String.Empty;

        public int ID
            get { return mID; }
            set { mID = value; }

        public string StateAbbr
            get { return mStateAbbr; }
            set { mStateAbbr = value; }

So we could deserialize it.

Page Provider

We should design a base interface to determine how page provider will retrieve the corresponding page and also filter and sort data:

public interface IPageProvider<t>
    List<t> GetDataPage(int pageNumber, int rowsPerPage);
    string Filter { get; set;}
    string Sort { get; set;}
    int RowCount { get;}


The cache class will be analogous to the one in MSDN article with the only difference that List<> class is used vs. DataTable class.


To use our cache as data source for the DataGridView, we should implement IBindingListView interface.

Server Side

At server side, web service will retrieve specified page of data and apply filtering and sorting. To demonstrate it, I've used Microsoft Access database and constructed SQL request to it.

How to Use the Code

  1. Place TestWebService source in some folder, for example C:\TestWebService 
  2. Place TestWinForm source in C:\TestWinForm 
  3. Run IIS 
  4. At default web site, create TestWebService virtual directory so that its source folder would be C:\TestWebService folder 
  5. Run TestWinForm app



  • 17th April, 2009: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Igor Kushnarev
Software Developer
Russian Federation Russian Federation
• More than 10 years experience in software development
• 3 years experience in direction of automation department.
• software engineering: experience in the whole life cycle of software development
• languages: Kotlin, Swift,Objective-C, C++, C#, Java, ASP.NET, HTML, XML, JavaScript, Visual FoxPro, MS SQL, T-SQL
• Gathering, specification and the analysis of requirements of the customer to the software.
• The analysis of a subject area.
• Estimations of labour input of development.
And so on...

Comments and Discussions

GeneralThanks Pin
YZK29-Mar-11 22:53
MemberYZK29-Mar-11 22:53 
GeneralConcerns about performance with large records numbers Pin
alan brett powell17-Jun-10 3:26
Memberalan brett powell17-Jun-10 3:26 
GeneralThank you Pin
amgadhs18-Apr-09 21:53
Memberamgadhs18-Apr-09 21:53 
GeneralThe code looks very useful, but the article lets it down Pin
Sacha Barber18-Apr-09 0:53
MemberSacha Barber18-Apr-09 0:53 
GeneralRe: The code looks very useful, but the article lets it down Pin
Igor Kushnarev18-Apr-09 3:05
professionalIgor Kushnarev18-Apr-09 3:05 
GeneralRe: The code looks very useful, but the article lets it down Pin
Sacha Barber18-Apr-09 3:09
MemberSacha Barber18-Apr-09 3:09 
GeneralRe: The code looks very useful, but the article lets it down Pin
Igor Kushnarev18-Apr-09 7:13
professionalIgor Kushnarev18-Apr-09 7:13 
GeneralRe: The code looks very useful, but the article lets it down Pin
Sacha Barber18-Apr-09 21:28
MemberSacha Barber18-Apr-09 21:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.