Home C# SimpleDatagridView Paging

C# SimpleDatagridView Paging

C# SimpleDatagridView Paging

Language :
Platform :
Type :

Details :

A simple user control to automatic paging in DataGridView .Net Framework.

Project Download Contributors

What is this?

This is a library provides a simple UserControl contains a DataGridView and a BindingNavigator. So, it can automatically paging in a simplest way.

Cool! How to use it?

Fist step, add library

Add this libary to your project. This is easy step, you just do something like below photo or use nuget.

Second step, drag-drop to form

Open your form in design mode(where you can drag-drop controls to design UI). See Toolbox, DataGridViewPaging control has been placed here. Just drag this control and then drop in your form where you want. It's similar other controls such as TextBox, Button, CheckBox....

Third step, coding

This step depends on your choices. This UserControl provides two ways to process request query are auto and manual.

Easiest way, let DataGridViewPaging do everything for you.

var connection = new SQLiteConnection("Data Source=chinook.db");
dataGridViewPaging.UserHardMode(connection, "tracks");

Result of this way. ## Heading ##

A little more option, you can define the query string for DataGridViewPaging instead of let it auto define.

var connection = new SQLiteConnection("Data Source=chinook.db");
dataGridViewPaging.UserSoftMode(connection, "SELECT Name, Composer, Bytes FROM tracks WHERE TrackId < 500");

Result of this way.

Let you do everything. You have to query database when DataGridViewPaging on demand.

var connection = new SQLiteConnection("Data Source=chinook.db");
// register request query event
dataGridViewPaging.RequestQueryData += DataGridViewPaging_RequestQueryData;
// set number of rows(records) and start query data
using (var command = connection.CreateCommand())
    command.CommandText = "SELECT COUNT(*) FROM tracks";
    var reader = command.ExecuteScalar();

private void DataGridViewPaging_RequestQueryData(object sender, RequestQueryDataEventArgs e)
    // query data and then set result to display
    using (var command = connection.CreateCommand())
        command.CommandText = "SELECT * FROM tracks LIMIT " + e.MaxRecords + " OFFSET " + e.PageOffset;
        dataGridViewPaging.DataSource = command.ExecuteReader();

Result of this way.

Wait! How can I get this libary?

Two ways.


This libary is already published to this location SimpleDataGridViewPaging. You can install by using this command:

Install-Package SimpleDataGridViewPaging

Also, a easier way is using NuGet Packages GUI in Visual Studio like this photo.


Of course, you can download standalone version here: https://github.com/sontx/simple-datagridview-paging/releases It contains source code and a binary file for library(compiled in net45).

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    6 − four =

    Leave a Comment

    three × 1 =