Skip to content

A simple UserControl that shows the data-table and paging automatically with .Net Framework

License

Notifications You must be signed in to change notification settings

sontx/simple-datagridview-paging

Repository files navigation

NuGet

simple-datagridview-paging is a simple UserControl that shows the data-table and paging automatically. With this library, you can also edit the data and it will be saved to the database automatically.

Only ONE line:

dataGridViewPaging.DbRequestHandler = DbRequestHandlerHelper.Create(new SQLiteConnection("Data Source=chinook.db"), "tracks");

Installation

Nuget:

Install-Package SimpleDataGridViewPaging

Or download binary file.

Usage

  1. Add the libary to the ToolBox: Right click to ToolBox -> Choose Item... -> In .Net Framework Components, click on Browse... and select the SimpleDataGridViewPaging.dll file then click OK.
  2. The DataGridViewPaging will be shown in the ToolBox like this:
  3. Drop&drag this control into your form.
  4. Code:
dataGridViewPaging.DbRequestHandler = DbRequestHandlerHelper.Create(new SQLiteConnection("Data Source=chinook.db"), "tracks");

There are two parameters: the connection and the table name that will be shown in the control.

  1. Enjoy ;)

More Options

There are several custom levels:

  1. Read-only mode:
// The first parameter is the database connection,
// the second one is the table name the will be queried and shown in the control.
dataGridViewPaging.DbRequestHandler = DbRequestHandlerHelper.Create(
    new SQLiteConnection("Data Source=chinook.db"),
    "tracks");
  1. Editable mode:
// Like the readonly mode but the third parameter is the CommandBuilder object. 
dataGridViewPaging.DbRequestHandler = DbRequestHandlerHelper.Create(
    new SQLiteConnection("Data Source=chinook.db"),
    "tracks",
    new SQLiteCommandBuilder(new SQLiteDataAdapter()));
  1. Custom query text:
// The libary will use this statement to query the number of records
// that need to caculate the pagination info.
var countStatementBuilder = new CountStatementBuilder();
countStatementBuilder.CommandText("SELECT COUNT(*) FROM tracks");

// This statement will be used to query the actually data of the table.
// There are 3 placeholders: {0} - table name, {1} - max records, {2} - page offset.
// The libary will pass corresponding data to these placeholders on demand.
var rowsStatementBuilder = new RowsStatementBuilder();
rowsStatementBuilder.CommandText("SELECT * FROM tracks LIMIT {1} OFFSET {2}");

dataGridViewPaging1.DbRequestHandler = new DbRequestHandler
{
    Connection = new SQLiteConnection("Data Source=chinook.db"),
    CountStatementBuilder = countStatementBuilder,
    RowsStatementBuilder = rowsStatementBuilder
};
  1. Manual querying. Take a look

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Dependencies

  • .Net Framework 4.5 or later.

Author

Developed by sontx/noem, some useful information:

License

MIT