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");
Nuget:
Install-Package SimpleDataGridViewPaging
Or download binary file.
- 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 ;)
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:
// 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
- 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
- .Net Framework 4.5 or later.
Developed by sontx/noem, some useful information:
- Home: www.code4bugs.com
- Blog: https://sontx.blogspot.com
- Email: [email protected]
- Twitter: @sontx0