simple-datagridview-paging
in Projects on C#, Database, Winform
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
- 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.
- The DataGridViewPaging will be shown in the ToolBox like this:
- Drop&drag this control into your form.
- 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.
- Enjoy ;)
More Options
There are several custom levels:
- 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");
- 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()));
- Custom query text: ``` cs // 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 }; ```
- Manual querying. Take a look
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Dependencies
- .Net Framework 4.5 or later.
Author
Developed by sontx/noem, some useful information:
- Blog: sontx.dev
- Email: xuanson33bk@gmail.com
- Twitter: @sontx0