├── .gitignore ├── Examples ├── App.config ├── AutoQueryWithEditableForm.Designer.cs ├── AutoQueryWithEditableForm.cs ├── AutoQueryWithEditableForm.resx ├── AutoQueryWithReadOnlyForm.Designer.cs ├── AutoQueryWithReadOnlyForm.cs ├── AutoQueryWithReadOnlyForm.resx ├── CustomQueryTextWithReadOnlyForm.Designer.cs ├── CustomQueryTextWithReadOnlyForm.cs ├── CustomQueryTextWithReadOnlyForm.resx ├── Examples.csproj ├── MainForm.Designer.cs ├── MainForm.cs ├── MainForm.resx ├── ManualQueryWithReadOnlyForm.Designer.cs ├── ManualQueryWithReadOnlyForm.cs ├── ManualQueryWithReadOnlyForm.resx ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── chinook.db └── packages.config ├── LICENSE ├── README.md ├── SimpleDataGridViewPaging.sln ├── SimpleDataGridViewPaging ├── DataGridViewPaging.Designer.cs ├── DataGridViewPaging.EventHandling.cs ├── DataGridViewPaging.Properties.cs ├── DataGridViewPaging.cs ├── DataGridViewPaging.resx ├── DbRequestHandler.cs ├── DbRequestHandlerHelper.cs ├── Exceptions │ └── QuantityRangeException.cs ├── IDbRequestHandler.cs ├── NavigatorHorizontal.cs ├── Properties │ └── AssemblyInfo.cs ├── ReadOnlyMode.cs ├── SimpleDataGridViewPaging.csproj └── Statement │ ├── AdapterStatement.cs │ ├── Builder │ ├── CountStatementBuilder.cs │ ├── RowsStatementBuilder.cs │ ├── StatementBuilder.cs │ └── UpdatableRowsStatementBuilder.cs │ ├── IStatement.cs │ ├── ReaderStatement.cs │ └── ScalarStatement.cs └── nuget ├── SimpleDataGridViewPaging.1.0.0.nupkg ├── SimpleDataGridViewPaging.2.0.0.nupkg ├── SimpleDataGridViewPaging.2.0.1.nupkg └── SimpleDataGridViewPaging.2.0.2.nupkg /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | -------------------------------------------------------------------------------- /Examples/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Examples/AutoQueryWithEditableForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Code4Bugs.SimpleDataGridViewPaging.Examples 2 | { 3 | partial class AutoQueryWithEditableForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.dataGridViewPaging1 = new Code4Bugs.SimpleDataGridViewPaging.DataGridViewPaging(); 32 | this.SuspendLayout(); 33 | // 34 | // dataGridViewPaging1 35 | // 36 | this.dataGridViewPaging1.AutoHideNavigator = false; 37 | this.dataGridViewPaging1.DataSource = null; 38 | this.dataGridViewPaging1.DbRequestHandler = null; 39 | this.dataGridViewPaging1.Dock = System.Windows.Forms.DockStyle.Fill; 40 | this.dataGridViewPaging1.Location = new System.Drawing.Point(0, 0); 41 | this.dataGridViewPaging1.Margin = new System.Windows.Forms.Padding(5); 42 | this.dataGridViewPaging1.MaxRecords = 100; 43 | this.dataGridViewPaging1.Name = "dataGridViewPaging1"; 44 | this.dataGridViewPaging1.Size = new System.Drawing.Size(616, 460); 45 | this.dataGridViewPaging1.TabIndex = 0; 46 | // 47 | // AutoQueryWithEditableForm 48 | // 49 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); 50 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 51 | this.ClientSize = new System.Drawing.Size(616, 460); 52 | this.Controls.Add(this.dataGridViewPaging1); 53 | this.Margin = new System.Windows.Forms.Padding(4); 54 | this.Name = "AutoQueryWithEditableForm"; 55 | this.Text = "Auto Query With Editable"; 56 | this.ResumeLayout(false); 57 | 58 | } 59 | 60 | #endregion 61 | 62 | private DataGridViewPaging dataGridViewPaging1; 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /Examples/AutoQueryWithEditableForm.cs: -------------------------------------------------------------------------------- 1 | using System.Data.SQLite; 2 | using System.Windows.Forms; 3 | 4 | namespace Code4Bugs.SimpleDataGridViewPaging.Examples 5 | { 6 | public partial class AutoQueryWithEditableForm : Form 7 | { 8 | public AutoQueryWithEditableForm() 9 | { 10 | InitializeComponent(); 11 | 12 | dataGridViewPaging1.DbRequestHandler = DbRequestHandlerHelper.Create( 13 | new SQLiteConnection("Data Source=chinook.db"), 14 | "tracks", 15 | new SQLiteCommandBuilder(new SQLiteDataAdapter())); 16 | 17 | // OR 18 | // dataGridViewPaging1.DbRequestHandler = new DbRequestHandler 19 | // { 20 | // Connection = new SQLiteConnection("Data Source=chinook.db"), 21 | // TableName = "tracks", 22 | // RowsStatementBuilder = new UpdatableRowsStatementBuilder().CommandBuilder(new SQLiteCommandBuilder(new SQLiteDataAdapter())) 23 | // }; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Examples/AutoQueryWithEditableForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /Examples/AutoQueryWithReadOnlyForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Code4Bugs.SimpleDataGridViewPaging.Examples 2 | { 3 | partial class AutoQueryWithReadOnlyForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.dataGridViewPaging1 = new Code4Bugs.SimpleDataGridViewPaging.DataGridViewPaging(); 32 | this.SuspendLayout(); 33 | // 34 | // dataGridViewPaging1 35 | // 36 | this.dataGridViewPaging1.AutoHideNavigator = false; 37 | this.dataGridViewPaging1.DataSource = null; 38 | this.dataGridViewPaging1.DbRequestHandler = null; 39 | this.dataGridViewPaging1.Dock = System.Windows.Forms.DockStyle.Fill; 40 | this.dataGridViewPaging1.Location = new System.Drawing.Point(0, 0); 41 | this.dataGridViewPaging1.Margin = new System.Windows.Forms.Padding(5); 42 | this.dataGridViewPaging1.MaxRecords = 100; 43 | this.dataGridViewPaging1.Name = "dataGridViewPaging1"; 44 | this.dataGridViewPaging1.Size = new System.Drawing.Size(616, 460); 45 | this.dataGridViewPaging1.TabIndex = 0; 46 | // 47 | // AutoQueryInReadOnlyForm 48 | // 49 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); 50 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 51 | this.ClientSize = new System.Drawing.Size(616, 460); 52 | this.Controls.Add(this.dataGridViewPaging1); 53 | this.Margin = new System.Windows.Forms.Padding(4); 54 | this.Name = "AutoQueryInReadOnlyForm"; 55 | this.Text = "Auto Query With ReadOnly"; 56 | this.ResumeLayout(false); 57 | 58 | } 59 | 60 | #endregion 61 | 62 | private DataGridViewPaging dataGridViewPaging1; 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /Examples/AutoQueryWithReadOnlyForm.cs: -------------------------------------------------------------------------------- 1 | using System.Data.SQLite; 2 | using System.Windows.Forms; 3 | 4 | namespace Code4Bugs.SimpleDataGridViewPaging.Examples 5 | { 6 | public partial class AutoQueryWithReadOnlyForm : Form 7 | { 8 | public AutoQueryWithReadOnlyForm() 9 | { 10 | InitializeComponent(); 11 | 12 | dataGridViewPaging1.DbRequestHandler = DbRequestHandlerHelper.Create( 13 | new SQLiteConnection("Data Source=chinook.db"), 14 | "tracks"); 15 | 16 | // OR 17 | // dataGridViewPaging1.DbRequestHandler = new DbRequestHandler 18 | // { 19 | // Connection = new SQLiteConnection("Data Source=chinook.db"), 20 | // TableName = "tracks" 21 | // }; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Examples/AutoQueryWithReadOnlyForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /Examples/CustomQueryTextWithReadOnlyForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Code4Bugs.SimpleDataGridViewPaging.Examples 2 | { 3 | partial class CustomQueryTextWithReadOnlyForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.dataGridViewPaging1 = new Code4Bugs.SimpleDataGridViewPaging.DataGridViewPaging(); 32 | this.SuspendLayout(); 33 | // 34 | // dataGridViewPaging1 35 | // 36 | this.dataGridViewPaging1.AutoHideNavigator = false; 37 | this.dataGridViewPaging1.DataSource = null; 38 | this.dataGridViewPaging1.DbRequestHandler = null; 39 | this.dataGridViewPaging1.Dock = System.Windows.Forms.DockStyle.Fill; 40 | this.dataGridViewPaging1.Location = new System.Drawing.Point(0, 0); 41 | this.dataGridViewPaging1.Margin = new System.Windows.Forms.Padding(5); 42 | this.dataGridViewPaging1.MaxRecords = 100; 43 | this.dataGridViewPaging1.Name = "dataGridViewPaging1"; 44 | this.dataGridViewPaging1.Size = new System.Drawing.Size(616, 460); 45 | this.dataGridViewPaging1.TabIndex = 0; 46 | // 47 | // CustomQueryTextWithReadOnlyForm 48 | // 49 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); 50 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 51 | this.ClientSize = new System.Drawing.Size(616, 460); 52 | this.Controls.Add(this.dataGridViewPaging1); 53 | this.Margin = new System.Windows.Forms.Padding(4); 54 | this.Name = "CustomQueryTextWithReadOnlyForm"; 55 | this.Text = "Custom Query Text With ReadOnly"; 56 | this.ResumeLayout(false); 57 | 58 | } 59 | 60 | #endregion 61 | 62 | private DataGridViewPaging dataGridViewPaging1; 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /Examples/CustomQueryTextWithReadOnlyForm.cs: -------------------------------------------------------------------------------- 1 | using System.Data.SQLite; 2 | using System.Windows.Forms; 3 | using Code4Bugs.SimpleDataGridViewPaging.Statement.Builder; 4 | 5 | namespace Code4Bugs.SimpleDataGridViewPaging.Examples 6 | { 7 | public partial class CustomQueryTextWithReadOnlyForm : Form 8 | { 9 | public CustomQueryTextWithReadOnlyForm() 10 | { 11 | InitializeComponent(); 12 | 13 | var countStatementBuilder = new CountStatementBuilder(); 14 | countStatementBuilder.CommandText("SELECT COUNT(*) FROM tracks"); 15 | 16 | var rowsStatementBuilder = new RowsStatementBuilder(); 17 | rowsStatementBuilder.CommandText("SELECT * FROM tracks LIMIT {1} OFFSET {2}"); 18 | 19 | dataGridViewPaging1.DbRequestHandler = new DbRequestHandler 20 | { 21 | Connection = new SQLiteConnection("Data Source=chinook.db"), 22 | CountStatementBuilder = countStatementBuilder, 23 | RowsStatementBuilder = rowsStatementBuilder 24 | }; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Examples/CustomQueryTextWithReadOnlyForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /Examples/Examples.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {2CC3510C-DB0B-4D64-B3DC-221D32A8DD45} 8 | WinExe 9 | Properties 10 | Code4Bugs.SimpleDataGridViewPaging.Examples 11 | Examples 12 | v4.5 13 | 512 14 | 15 | 16 | 17 | 18 | AnyCPU 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | AnyCPU 29 | pdbonly 30 | true 31 | bin\Release\ 32 | TRACE 33 | prompt 34 | 4 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | ..\packages\System.Data.SQLite.Core.1.0.108.0\lib\net45\System.Data.SQLite.dll 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | Form 56 | 57 | 58 | AutoQueryWithEditableForm.cs 59 | 60 | 61 | Form 62 | 63 | 64 | MainForm.cs 65 | 66 | 67 | Form 68 | 69 | 70 | ManualQueryWithReadOnlyForm.cs 71 | 72 | 73 | Form 74 | 75 | 76 | CustomQueryTextWithReadOnlyForm.cs 77 | 78 | 79 | Form 80 | 81 | 82 | AutoQueryWithReadOnlyForm.cs 83 | 84 | 85 | 86 | 87 | AutoQueryWithEditableForm.cs 88 | 89 | 90 | MainForm.cs 91 | 92 | 93 | ManualQueryWithReadOnlyForm.cs 94 | 95 | 96 | CustomQueryTextWithReadOnlyForm.cs 97 | 98 | 99 | AutoQueryWithReadOnlyForm.cs 100 | 101 | 102 | ResXFileCodeGenerator 103 | Resources.Designer.cs 104 | Designer 105 | 106 | 107 | True 108 | Resources.resx 109 | True 110 | 111 | 112 | PreserveNewest 113 | 114 | 115 | 116 | SettingsSingleFileGenerator 117 | Settings.Designer.cs 118 | 119 | 120 | True 121 | Settings.settings 122 | True 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | {8784a91a-10e1-4f2d-a233-eaf60275f2f0} 131 | SimpleDataGridViewPaging 132 | 133 | 134 | 135 | 136 | 137 | 138 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 139 | 140 | 141 | 142 | 149 | -------------------------------------------------------------------------------- /Examples/MainForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Code4Bugs.SimpleDataGridViewPaging.Examples 2 | { 3 | partial class MainForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.button1 = new System.Windows.Forms.Button(); 32 | this.button2 = new System.Windows.Forms.Button(); 33 | this.button3 = new System.Windows.Forms.Button(); 34 | this.button4 = new System.Windows.Forms.Button(); 35 | this.SuspendLayout(); 36 | // 37 | // button1 38 | // 39 | this.button1.Location = new System.Drawing.Point(40, 39); 40 | this.button1.Name = "button1"; 41 | this.button1.Size = new System.Drawing.Size(237, 52); 42 | this.button1.TabIndex = 0; 43 | this.button1.Text = "Auto Query With Reaonly"; 44 | this.button1.UseVisualStyleBackColor = true; 45 | this.button1.Click += new System.EventHandler(this.button1_Click); 46 | // 47 | // button2 48 | // 49 | this.button2.Location = new System.Drawing.Point(40, 97); 50 | this.button2.Name = "button2"; 51 | this.button2.Size = new System.Drawing.Size(237, 52); 52 | this.button2.TabIndex = 0; 53 | this.button2.Text = "Auto Query With Editable"; 54 | this.button2.UseVisualStyleBackColor = true; 55 | this.button2.Click += new System.EventHandler(this.button2_Click); 56 | // 57 | // button3 58 | // 59 | this.button3.Location = new System.Drawing.Point(40, 155); 60 | this.button3.Name = "button3"; 61 | this.button3.Size = new System.Drawing.Size(237, 52); 62 | this.button3.TabIndex = 0; 63 | this.button3.Text = "Custom Query Text With ReadOnly"; 64 | this.button3.UseVisualStyleBackColor = true; 65 | this.button3.Click += new System.EventHandler(this.button3_Click); 66 | // 67 | // button4 68 | // 69 | this.button4.Location = new System.Drawing.Point(40, 213); 70 | this.button4.Name = "button4"; 71 | this.button4.Size = new System.Drawing.Size(237, 52); 72 | this.button4.TabIndex = 0; 73 | this.button4.Text = "Manual Query With ReadOnly"; 74 | this.button4.UseVisualStyleBackColor = true; 75 | this.button4.Click += new System.EventHandler(this.button4_Click); 76 | // 77 | // MainForm 78 | // 79 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); 80 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 81 | this.ClientSize = new System.Drawing.Size(318, 299); 82 | this.Controls.Add(this.button4); 83 | this.Controls.Add(this.button3); 84 | this.Controls.Add(this.button2); 85 | this.Controls.Add(this.button1); 86 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 87 | this.MaximizeBox = false; 88 | this.MinimizeBox = false; 89 | this.Name = "MainForm"; 90 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 91 | this.Text = "MainForm"; 92 | this.ResumeLayout(false); 93 | 94 | } 95 | 96 | #endregion 97 | 98 | private System.Windows.Forms.Button button1; 99 | private System.Windows.Forms.Button button2; 100 | private System.Windows.Forms.Button button3; 101 | private System.Windows.Forms.Button button4; 102 | } 103 | } -------------------------------------------------------------------------------- /Examples/MainForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace Code4Bugs.SimpleDataGridViewPaging.Examples 5 | { 6 | public partial class MainForm : Form 7 | { 8 | public MainForm() 9 | { 10 | InitializeComponent(); 11 | } 12 | 13 | private void button1_Click(object sender, EventArgs e) 14 | { 15 | using (var form = new AutoQueryWithReadOnlyForm()) 16 | { 17 | form.ShowDialog(this); 18 | } 19 | } 20 | 21 | private void button2_Click(object sender, EventArgs e) 22 | { 23 | using (var form = new AutoQueryWithEditableForm()) 24 | { 25 | form.ShowDialog(this); 26 | } 27 | } 28 | 29 | private void button3_Click(object sender, EventArgs e) 30 | { 31 | using (var form = new CustomQueryTextWithReadOnlyForm()) 32 | { 33 | form.ShowDialog(this); 34 | } 35 | } 36 | 37 | private void button4_Click(object sender, EventArgs e) 38 | { 39 | using (var form = new ManualQueryWithReadOnlyForm()) 40 | { 41 | form.ShowDialog(this); 42 | } 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /Examples/MainForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | True 122 | 123 | 124 | True 125 | 126 | 127 | True 128 | 129 | 130 | True 131 | 132 | 133 | True 134 | 135 | -------------------------------------------------------------------------------- /Examples/ManualQueryWithReadOnlyForm.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Code4Bugs.SimpleDataGridViewPaging.Examples 2 | { 3 | partial class ManualQueryWithReadOnlyForm 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.dataGridViewPaging1 = new Code4Bugs.SimpleDataGridViewPaging.DataGridViewPaging(); 32 | this.SuspendLayout(); 33 | // 34 | // dataGridViewPaging1 35 | // 36 | this.dataGridViewPaging1.AutoHideNavigator = false; 37 | this.dataGridViewPaging1.DataSource = null; 38 | this.dataGridViewPaging1.DbRequestHandler = null; 39 | this.dataGridViewPaging1.Dock = System.Windows.Forms.DockStyle.Fill; 40 | this.dataGridViewPaging1.Location = new System.Drawing.Point(0, 0); 41 | this.dataGridViewPaging1.Margin = new System.Windows.Forms.Padding(5); 42 | this.dataGridViewPaging1.MaxRecords = 100; 43 | this.dataGridViewPaging1.Name = "dataGridViewPaging1"; 44 | this.dataGridViewPaging1.Size = new System.Drawing.Size(616, 460); 45 | this.dataGridViewPaging1.TabIndex = 0; 46 | // 47 | // CustomQueryWithReadOnlyForm 48 | // 49 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); 50 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 51 | this.ClientSize = new System.Drawing.Size(616, 460); 52 | this.Controls.Add(this.dataGridViewPaging1); 53 | this.Margin = new System.Windows.Forms.Padding(4); 54 | this.Name = "CustomQueryWithReadOnlyForm"; 55 | this.Text = "Custom Query With ReadOnly"; 56 | this.ResumeLayout(false); 57 | 58 | } 59 | 60 | #endregion 61 | 62 | private DataGridViewPaging dataGridViewPaging1; 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /Examples/ManualQueryWithReadOnlyForm.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.Common; 3 | using System.Data.SQLite; 4 | using System.Windows.Forms; 5 | using Code4Bugs.SimpleDataGridViewPaging.Statement; 6 | using Code4Bugs.SimpleDataGridViewPaging.Statement.Builder; 7 | 8 | namespace Code4Bugs.SimpleDataGridViewPaging.Examples 9 | { 10 | public partial class ManualQueryWithReadOnlyForm : Form 11 | { 12 | public ManualQueryWithReadOnlyForm() 13 | { 14 | InitializeComponent(); 15 | 16 | var rowsStatementBuilder = new RowsStatementBuilder(); 17 | rowsStatementBuilder.CommandText("SELECT * FROM tracks LIMIT {1} OFFSET {2}"); 18 | 19 | dataGridViewPaging1.DbRequestHandler = new DbRequestHandler 20 | { 21 | Connection = new SQLiteConnection("Data Source=chinook.db"), 22 | CountStatementBuilder = new CustomCountStatementBuilder(), 23 | RowsStatementBuilder = new CustomRowsStatementBuilder() 24 | }; 25 | } 26 | 27 | private class CustomCountStatementBuilder : CountStatementBuilder 28 | { 29 | public override IStatement Build() 30 | { 31 | return new CountStatement {Connection = _connection}; 32 | } 33 | 34 | private class CountStatement : IStatement 35 | { 36 | public DbConnection Connection { get; set; } 37 | 38 | public int Execute() 39 | { 40 | using (var command = Connection.CreateCommand()) 41 | { 42 | command.CommandText = "SELECT COUNT(*) FROM tracks"; 43 | var result = command.ExecuteScalar(); 44 | return Convert.ToInt32(result); 45 | } 46 | } 47 | } 48 | } 49 | 50 | private class CustomRowsStatementBuilder : RowsStatementBuilder 51 | { 52 | public override IStatement Build() 53 | { 54 | return new RowsStatement 55 | { 56 | Connection = _connection, 57 | MaxRecords = _maxRecords, 58 | PageOffset = _pageOffset 59 | }; 60 | } 61 | 62 | private class RowsStatement : IStatement 63 | { 64 | public DbConnection Connection { get; set; } 65 | public int MaxRecords { get; set; } 66 | public int PageOffset { get; set; } 67 | 68 | public object Execute() 69 | { 70 | using (var command = Connection.CreateCommand()) 71 | { 72 | command.CommandText = $"SELECT * FROM tracks LIMIT {MaxRecords} OFFSET {PageOffset}"; 73 | return command.ExecuteReader(); 74 | } 75 | } 76 | } 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /Examples/ManualQueryWithReadOnlyForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /Examples/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace Code4Bugs.SimpleDataGridViewPaging.Examples 5 | { 6 | internal static class Program 7 | { 8 | /// 9 | /// The main entry point for the application. 10 | /// 11 | [STAThread] 12 | private static void Main() 13 | { 14 | Application.EnableVisualStyles(); 15 | Application.SetCompatibleTextRenderingDefault(false); 16 | Application.Run(new MainForm()); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Examples/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Test")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Test")] 13 | [assembly: AssemblyCopyright("Copyright © 2016")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("2cc3510c-db0b-4d64-b3dc-221d32a8dd45")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Examples/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Code4Bugs.SimpleDataGridViewPaging.Examples.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Code4Bugs.SimpleDataGridViewPaging.Examples.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Examples/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /Examples/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace Code4Bugs.SimpleDataGridViewPaging.Examples.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.6.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Examples/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Examples/chinook.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sontx/simple-datagridview-paging/e78458ec5537c03aeb6409da555b98ffd90edc4e/Examples/chinook.db -------------------------------------------------------------------------------- /Examples/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 No Em 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![NuGet](https://buildstats.info/nuget/SimpleDataGridViewPaging) 2 | 3 | **simple-datagridview-paging** is a simple UserControl that shows the data-table and paging automatically. 4 | With this library, you can also edit the data and it will be saved to the database automatically. 5 | ![](https://3.bp.blogspot.com/-76IqcXrupWc/Wzzowu0OxNI/AAAAAAAAVRs/J2Xwqp4aN7ce02rEfMB47HmlGxQpwoYOgCLcBGAs/Capture.PNG) 6 | 7 | Only ONE line: 8 | ``` cs 9 | dataGridViewPaging.DbRequestHandler = DbRequestHandlerHelper.Create(new SQLiteConnection("Data Source=chinook.db"), "tracks"); 10 | ``` 11 | 12 | ## Installation 13 | Nuget: 14 | 15 | > Install-Package SimpleDataGridViewPaging 16 | 17 | Or download [binary file](https://github.com/sontx/simple-datagridview-paging/releases). 18 | 19 | ## Usage 20 | 21 | 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**. 22 | 2. The **DataGridViewPaging** will be shown in the **ToolBox** like this: ![](https://camo.githubusercontent.com/a9e6ae4695fdac87b32f247b001bbd00622cd1bb/68747470733a2f2f6c68332e676f6f676c6575736572636f6e74656e742e636f6d2f2d7448727779656c73724a672f5636625778556b79484c492f414141414141414150646f2f713473314163794c636b59696e61527054545a4235316f70697941704252345077434b67422f73302f436170747572652e504e47) 23 | 3. Drop&drag this control into your form. 24 | 4. Code: 25 | ``` cs 26 | dataGridViewPaging.DbRequestHandler = DbRequestHandlerHelper.Create(new SQLiteConnection("Data Source=chinook.db"), "tracks"); 27 | ``` 28 | 29 | > There are two parameters: the connection and the table name that will be shown in the control. 30 | 31 | 5. Enjoy ;) 32 | 33 | ### More Options 34 | There are several custom levels: 35 | 1. Read-only mode: 36 | 37 | ``` cs 38 | // The first parameter is the database connection, 39 | // the second one is the table name the will be queried and shown in the control. 40 | dataGridViewPaging.DbRequestHandler = DbRequestHandlerHelper.Create( 41 | new SQLiteConnection("Data Source=chinook.db"), 42 | "tracks"); 43 | ``` 44 | 45 | 2. Editable mode: 46 | ``` cs 47 | // Like the readonly mode but the third parameter is the CommandBuilder object. 48 | dataGridViewPaging.DbRequestHandler = DbRequestHandlerHelper.Create( 49 | new SQLiteConnection("Data Source=chinook.db"), 50 | "tracks", 51 | new SQLiteCommandBuilder(new SQLiteDataAdapter())); 52 | ``` 53 | 54 | 3. Custom query text: 55 | ``` cs 56 | // The libary will use this statement to query the number of records 57 | // that need to caculate the pagination info. 58 | var countStatementBuilder = new CountStatementBuilder(); 59 | countStatementBuilder.CommandText("SELECT COUNT(*) FROM tracks"); 60 | 61 | // This statement will be used to query the actually data of the table. 62 | // There are 3 placeholders: {0} - table name, {1} - max records, {2} - page offset. 63 | // The libary will pass corresponding data to these placeholders on demand. 64 | var rowsStatementBuilder = new RowsStatementBuilder(); 65 | rowsStatementBuilder.CommandText("SELECT * FROM tracks LIMIT {1} OFFSET {2}"); 66 | 67 | dataGridViewPaging1.DbRequestHandler = new DbRequestHandler 68 | { 69 | Connection = new SQLiteConnection("Data Source=chinook.db"), 70 | CountStatementBuilder = countStatementBuilder, 71 | RowsStatementBuilder = rowsStatementBuilder 72 | }; 73 | ``` 74 | 75 | 4. Manual querying. [Take a look](https://github.com/sontx/simple-datagridview-paging/blob/master/Examples/ManualQueryWithReadOnlyForm.cs) 76 | 77 | ## Contributing 78 | 1. Fork it! 79 | 2. Create your feature branch: `git checkout -b my-new-feature` 80 | 3. Commit your changes: `git commit -am 'Add some feature'` 81 | 4. Push to the branch: `git push origin my-new-feature` 82 | 5. Submit a pull request :D 83 | 84 | ## Dependencies 85 | 86 | - .Net Framework 4.5 or later. 87 | 88 | ## Author 89 | Developed by sontx/noem, some useful information: 90 | 91 | - Home: [www.code4bugs.com](https://code4bugs.com) 92 | - Blog: [https://sontx.blogspot.com](https://sontx.blogspot.com) 93 | - Email: xuanson33bk@gmail.com 94 | - Twitter: [@sontx0](https://twitter.com/sontx0) 95 | 96 | ## License 97 | [MIT](https://github.com/sontx/simple-datagridview-paging/blob/master/LICENSE) 98 | -------------------------------------------------------------------------------- /SimpleDataGridViewPaging.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27428.2037 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleDataGridViewPaging", "SimpleDataGridViewPaging\SimpleDataGridViewPaging.csproj", "{8784A91A-10E1-4F2D-A233-EAF60275F2F0}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Examples", "Examples\Examples.csproj", "{2CC3510C-DB0B-4D64-B3DC-221D32A8DD45}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {8784A91A-10E1-4F2D-A233-EAF60275F2F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {8784A91A-10E1-4F2D-A233-EAF60275F2F0}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {8784A91A-10E1-4F2D-A233-EAF60275F2F0}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {8784A91A-10E1-4F2D-A233-EAF60275F2F0}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {2CC3510C-DB0B-4D64-B3DC-221D32A8DD45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {2CC3510C-DB0B-4D64-B3DC-221D32A8DD45}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {2CC3510C-DB0B-4D64-B3DC-221D32A8DD45}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {2CC3510C-DB0B-4D64-B3DC-221D32A8DD45}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {DFF748D3-C061-4B48-9E74-8ED3FE9D44A6} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/DataGridViewPaging.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Code4Bugs.SimpleDataGridViewPaging 2 | { 3 | partial class DataGridViewPaging 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DataGridViewPaging)); 32 | this.GridView = new System.Windows.Forms.DataGridView(); 33 | this.bindingSource = new System.Windows.Forms.BindingSource(); 34 | this.panel1 = new System.Windows.Forms.Panel(); 35 | this._navigator = new System.Windows.Forms.BindingNavigator(); 36 | this.bindingNavigatorCountItem = new System.Windows.Forms.ToolStripLabel(); 37 | this.bindingNavigatorMoveFirstItem = new System.Windows.Forms.ToolStripButton(); 38 | this.bindingNavigatorMovePreviousItem = new System.Windows.Forms.ToolStripButton(); 39 | this.bindingNavigatorSeparator = new System.Windows.Forms.ToolStripSeparator(); 40 | this.bindingNavigatorPositionItem = new System.Windows.Forms.ToolStripTextBox(); 41 | this.bindingNavigatorSeparator1 = new System.Windows.Forms.ToolStripSeparator(); 42 | this.bindingNavigatorMoveNextItem = new System.Windows.Forms.ToolStripButton(); 43 | this.bindingNavigatorMoveLastItem = new System.Windows.Forms.ToolStripButton(); 44 | ((System.ComponentModel.ISupportInitialize)(this.GridView)).BeginInit(); 45 | ((System.ComponentModel.ISupportInitialize)(this.bindingSource)).BeginInit(); 46 | this.panel1.SuspendLayout(); 47 | ((System.ComponentModel.ISupportInitialize)(this._navigator)).BeginInit(); 48 | this._navigator.SuspendLayout(); 49 | this.SuspendLayout(); 50 | // 51 | // _gridView 52 | // 53 | this.GridView.AutoGenerateColumns = false; 54 | this.GridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; 55 | this.GridView.DataSource = this.bindingSource; 56 | this.GridView.Dock = System.Windows.Forms.DockStyle.Fill; 57 | this.GridView.Location = new System.Drawing.Point(0, 0); 58 | this.GridView.Margin = new System.Windows.Forms.Padding(4); 59 | this.GridView.Name = "GridView"; 60 | this.GridView.Size = new System.Drawing.Size(440, 271); 61 | this.GridView.TabIndex = 0; 62 | this.GridView.DataBindingComplete += new System.Windows.Forms.DataGridViewBindingCompleteEventHandler(this.dataGridView_DataBindingComplete); 63 | // 64 | // panel1 65 | // 66 | this.panel1.Controls.Add(this._navigator); 67 | this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; 68 | this.panel1.Location = new System.Drawing.Point(0, 271); 69 | this.panel1.Margin = new System.Windows.Forms.Padding(4); 70 | this.panel1.Name = "panel1"; 71 | this.panel1.Size = new System.Drawing.Size(440, 47); 72 | this.panel1.TabIndex = 1; 73 | // 74 | // _navigator 75 | // 76 | this._navigator.AddNewItem = null; 77 | this._navigator.CountItem = this.bindingNavigatorCountItem; 78 | this._navigator.DeleteItem = null; 79 | this._navigator.Dock = System.Windows.Forms.DockStyle.Fill; 80 | this._navigator.GripStyle = System.Windows.Forms.ToolStripGripStyle.Hidden; 81 | this._navigator.ImageScalingSize = new System.Drawing.Size(20, 20); 82 | this._navigator.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 83 | this.bindingNavigatorMoveFirstItem, 84 | this.bindingNavigatorMovePreviousItem, 85 | this.bindingNavigatorSeparator, 86 | this.bindingNavigatorPositionItem, 87 | this.bindingNavigatorCountItem, 88 | this.bindingNavigatorSeparator1, 89 | this.bindingNavigatorMoveNextItem, 90 | this.bindingNavigatorMoveLastItem}); 91 | this._navigator.Location = new System.Drawing.Point(0, 0); 92 | this._navigator.MoveFirstItem = this.bindingNavigatorMoveFirstItem; 93 | this._navigator.MoveLastItem = this.bindingNavigatorMoveLastItem; 94 | this._navigator.MoveNextItem = this.bindingNavigatorMoveNextItem; 95 | this._navigator.MovePreviousItem = this.bindingNavigatorMovePreviousItem; 96 | this._navigator.Name = "_navigator"; 97 | this._navigator.PositionItem = this.bindingNavigatorPositionItem; 98 | this._navigator.Size = new System.Drawing.Size(440, 47); 99 | this._navigator.TabIndex = 0; 100 | // 101 | // bindingNavigatorCountItem 102 | // 103 | this.bindingNavigatorCountItem.Name = "bindingNavigatorCountItem"; 104 | this.bindingNavigatorCountItem.Size = new System.Drawing.Size(45, 44); 105 | this.bindingNavigatorCountItem.Text = "of {0}"; 106 | this.bindingNavigatorCountItem.ToolTipText = "Total number of items"; 107 | // 108 | // bindingNavigatorMoveFirstItem 109 | // 110 | this.bindingNavigatorMoveFirstItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 111 | this.bindingNavigatorMoveFirstItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorMoveFirstItem.Image"))); 112 | this.bindingNavigatorMoveFirstItem.Name = "bindingNavigatorMoveFirstItem"; 113 | this.bindingNavigatorMoveFirstItem.RightToLeftAutoMirrorImage = true; 114 | this.bindingNavigatorMoveFirstItem.Size = new System.Drawing.Size(24, 44); 115 | this.bindingNavigatorMoveFirstItem.Text = "Move first"; 116 | this.bindingNavigatorMoveFirstItem.Click += new System.EventHandler(this.bindingNavigatorMoveFirstItem_Click); 117 | // 118 | // bindingNavigatorMovePreviousItem 119 | // 120 | this.bindingNavigatorMovePreviousItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 121 | this.bindingNavigatorMovePreviousItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorMovePreviousItem.Image"))); 122 | this.bindingNavigatorMovePreviousItem.Name = "bindingNavigatorMovePreviousItem"; 123 | this.bindingNavigatorMovePreviousItem.RightToLeftAutoMirrorImage = true; 124 | this.bindingNavigatorMovePreviousItem.Size = new System.Drawing.Size(24, 44); 125 | this.bindingNavigatorMovePreviousItem.Text = "Move previous"; 126 | this.bindingNavigatorMovePreviousItem.Click += new System.EventHandler(this.bindingNavigatorMovePreviousItem_Click); 127 | // 128 | // bindingNavigatorSeparator 129 | // 130 | this.bindingNavigatorSeparator.Name = "bindingNavigatorSeparator"; 131 | this.bindingNavigatorSeparator.Size = new System.Drawing.Size(6, 47); 132 | // 133 | // bindingNavigatorPositionItem 134 | // 135 | this.bindingNavigatorPositionItem.AccessibleName = "Position"; 136 | this.bindingNavigatorPositionItem.AutoSize = false; 137 | this.bindingNavigatorPositionItem.Name = "bindingNavigatorPositionItem"; 138 | this.bindingNavigatorPositionItem.Size = new System.Drawing.Size(65, 27); 139 | this.bindingNavigatorPositionItem.Text = "0"; 140 | this.bindingNavigatorPositionItem.ToolTipText = "Current position"; 141 | this.bindingNavigatorPositionItem.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.bindingNavigatorPositionItem_KeyPress); 142 | // 143 | // bindingNavigatorSeparator1 144 | // 145 | this.bindingNavigatorSeparator1.Name = "bindingNavigatorSeparator1"; 146 | this.bindingNavigatorSeparator1.Size = new System.Drawing.Size(6, 47); 147 | // 148 | // bindingNavigatorMoveNextItem 149 | // 150 | this.bindingNavigatorMoveNextItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 151 | this.bindingNavigatorMoveNextItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorMoveNextItem.Image"))); 152 | this.bindingNavigatorMoveNextItem.Name = "bindingNavigatorMoveNextItem"; 153 | this.bindingNavigatorMoveNextItem.RightToLeftAutoMirrorImage = true; 154 | this.bindingNavigatorMoveNextItem.Size = new System.Drawing.Size(24, 44); 155 | this.bindingNavigatorMoveNextItem.Text = "Move next"; 156 | this.bindingNavigatorMoveNextItem.Click += new System.EventHandler(this.bindingNavigatorMoveNextItem_Click); 157 | // 158 | // bindingNavigatorMoveLastItem 159 | // 160 | this.bindingNavigatorMoveLastItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; 161 | this.bindingNavigatorMoveLastItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorMoveLastItem.Image"))); 162 | this.bindingNavigatorMoveLastItem.Name = "bindingNavigatorMoveLastItem"; 163 | this.bindingNavigatorMoveLastItem.RightToLeftAutoMirrorImage = true; 164 | this.bindingNavigatorMoveLastItem.Size = new System.Drawing.Size(24, 44); 165 | this.bindingNavigatorMoveLastItem.Text = "Move last"; 166 | this.bindingNavigatorMoveLastItem.Click += new System.EventHandler(this.bindingNavigatorMoveLastItem_Click); 167 | // 168 | // DataGridViewPaging 169 | // 170 | this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); 171 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 172 | this.Controls.Add(this.GridView); 173 | this.Controls.Add(this.panel1); 174 | this.Margin = new System.Windows.Forms.Padding(4); 175 | this.Name = "DataGridViewPaging"; 176 | this.Size = new System.Drawing.Size(440, 318); 177 | ((System.ComponentModel.ISupportInitialize)(this.GridView)).EndInit(); 178 | ((System.ComponentModel.ISupportInitialize)(this.bindingSource)).EndInit(); 179 | this.panel1.ResumeLayout(false); 180 | this.panel1.PerformLayout(); 181 | ((System.ComponentModel.ISupportInitialize)(this._navigator)).EndInit(); 182 | this._navigator.ResumeLayout(false); 183 | this._navigator.PerformLayout(); 184 | this.ResumeLayout(false); 185 | 186 | } 187 | 188 | #endregion 189 | 190 | private System.Windows.Forms.Panel panel1; 191 | private System.Windows.Forms.BindingNavigator _navigator; 192 | private System.Windows.Forms.ToolStripLabel bindingNavigatorCountItem; 193 | private System.Windows.Forms.ToolStripButton bindingNavigatorMoveFirstItem; 194 | private System.Windows.Forms.ToolStripButton bindingNavigatorMovePreviousItem; 195 | private System.Windows.Forms.ToolStripSeparator bindingNavigatorSeparator; 196 | private System.Windows.Forms.ToolStripTextBox bindingNavigatorPositionItem; 197 | private System.Windows.Forms.ToolStripSeparator bindingNavigatorSeparator1; 198 | private System.Windows.Forms.ToolStripButton bindingNavigatorMoveNextItem; 199 | private System.Windows.Forms.ToolStripButton bindingNavigatorMoveLastItem; 200 | private System.Windows.Forms.BindingSource bindingSource; 201 | } 202 | } 203 | -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/DataGridViewPaging.EventHandling.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | 4 | namespace Code4Bugs.SimpleDataGridViewPaging 5 | { 6 | public partial class DataGridViewPaging 7 | { 8 | private void DataGridViewPaging_Disposed(object sender, EventArgs e) 9 | { 10 | Disposed -= DataGridViewPaging_Disposed; 11 | DbRequestHandler?.Dispose(); 12 | } 13 | 14 | private void dataGridView_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) 15 | { 16 | if (InvokeRequired) 17 | BeginInvoke((MethodInvoker) UpdateNavigatorButtons); 18 | else 19 | UpdateNavigatorButtons(); 20 | } 21 | 22 | private void bindingNavigatorMoveFirstItem_Click(object sender, EventArgs e) 23 | { 24 | _currentPageOffset = 0; 25 | QueryData(); 26 | } 27 | 28 | private void bindingNavigatorMovePreviousItem_Click(object sender, EventArgs e) 29 | { 30 | _currentPageOffset -= MaxRecords; 31 | QueryData(); 32 | } 33 | 34 | private void bindingNavigatorMoveNextItem_Click(object sender, EventArgs e) 35 | { 36 | _currentPageOffset += MaxRecords; 37 | QueryData(); 38 | } 39 | 40 | private void bindingNavigatorMoveLastItem_Click(object sender, EventArgs e) 41 | { 42 | _currentPageOffset = (TotalPages - 1) * MaxRecords; 43 | QueryData(); 44 | } 45 | 46 | private void bindingNavigatorPositionItem_KeyPress(object sender, KeyPressEventArgs e) 47 | { 48 | if (e.KeyChar != (char) Keys.Enter) return; 49 | 50 | if (int.TryParse(bindingNavigatorPositionItem.Text, out var pageNumber)) 51 | { 52 | if (pageNumber == CurrentPage) return; 53 | 54 | var totalPages = TotalPages; 55 | if (pageNumber >= 1 && pageNumber <= totalPages) 56 | { 57 | _currentPageOffset = (pageNumber - 1) * MaxRecords; 58 | QueryData(); 59 | } 60 | else 61 | { 62 | MessageBox.Show($@"Page number must be from 1 to {totalPages}.", Application.ProductName); 63 | } 64 | } 65 | else 66 | { 67 | MessageBox.Show(@"You must enter a page number to navigate.", Application.ProductName); 68 | bindingNavigatorPositionItem.Text = CurrentPage.ToString(); 69 | } 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/DataGridViewPaging.Properties.cs: -------------------------------------------------------------------------------- 1 | using System.ComponentModel; 2 | using System.Windows.Forms; 3 | using Code4Bugs.SimpleDataGridViewPaging.Exceptions; 4 | 5 | namespace Code4Bugs.SimpleDataGridViewPaging 6 | { 7 | public partial class DataGridViewPaging 8 | { 9 | private const string CategoryControl = "Control"; 10 | private const string CategoryBehavior = "Behavior"; 11 | private NavigatorHorizontal _navigatorHorizontal; 12 | 13 | [Browsable(true)] 14 | [Description("The original DataGridView control.")] 15 | [Category(CategoryControl)] 16 | public DataGridView GridView { get; private set; } 17 | 18 | [Browsable(true)] 19 | [Description("The original BindingNavigator control.")] 20 | [Category(CategoryControl)] 21 | public BindingNavigator Navigator => _navigator; 22 | 23 | [Browsable(true)] 24 | [DefaultValue(typeof(ReadOnlyMode), "Default")] 25 | [Description("Gets or sets a value indicating whether DataGridView in the DataGridViewPaging is read-only.")] 26 | [Category(CategoryBehavior)] 27 | public ReadOnlyMode ReadOnly 28 | { 29 | get => _readonly; 30 | set 31 | { 32 | _readonly = value; 33 | 34 | if (_readonly != ReadOnlyMode.Default) 35 | { 36 | ComputedReadOnly = _readonly == ReadOnlyMode.True; 37 | GridView.ReadOnly = ComputedReadOnly; 38 | } 39 | } 40 | } 41 | 42 | [Browsable(true)] 43 | [Description("Gets or sets max records for each page.")] 44 | [Category(CategoryBehavior)] 45 | public int MaxRecords 46 | { 47 | get => _maxRecords; 48 | set 49 | { 50 | if (value < 1) 51 | throw new QuantityRangeException("Max records must be at least 1."); 52 | _maxRecords = value; 53 | } 54 | } 55 | 56 | [Browsable(true)] 57 | [Description("Gets or whether the navigator is hidden if necessary.")] 58 | [Category(CategoryBehavior)] 59 | public bool AutoHideNavigator 60 | { 61 | get => _autoHideNavigator; 62 | set 63 | { 64 | _autoHideNavigator = value; 65 | _navigator.Visible = !(_autoHideNavigator && IsNotPaging); 66 | } 67 | } 68 | 69 | [Browsable(false)] 70 | [Description("Gets current page.")] 71 | public int CurrentPage => _currentPageOffset / _maxRecords + 1; 72 | 73 | [Browsable(false)] 74 | [Description("Gets total pages.")] 75 | public int TotalPages => (_numberOfRecords - 1) / _maxRecords + 1; 76 | 77 | [Browsable(false)] 78 | [Description("Gets or sets data source for DataGridViewPaging.")] 79 | public object DataSource 80 | { 81 | get => bindingSource.DataSource; 82 | set 83 | { 84 | if (InvokeRequired) 85 | { 86 | BeginInvoke((MethodInvoker) delegate 87 | { 88 | bindingSource.DataSource = value; 89 | ComputeReadOnlyIfNecessary(); 90 | }); 91 | } 92 | else 93 | { 94 | bindingSource.DataSource = value; 95 | ComputeReadOnlyIfNecessary(); 96 | } 97 | } 98 | } 99 | 100 | [Browsable(true)] 101 | [Description("Gets or sets horizontally of navigator.")] 102 | [Category(CategoryBehavior)] 103 | public NavigatorHorizontal NavigatorHorizontal 104 | { 105 | get => _navigatorHorizontal; 106 | set 107 | { 108 | _navigatorHorizontal = value; 109 | UpdateNavigatorHorizontal(); 110 | } 111 | } 112 | } 113 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/DataGridViewPaging.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Windows.Forms; 4 | using Code4Bugs.SimpleDataGridViewPaging.Exceptions; 5 | 6 | namespace Code4Bugs.SimpleDataGridViewPaging 7 | { 8 | /// 9 | /// 10 | /// The contains a 11 | /// and a and it's capable of paging automatically. 12 | /// 13 | public partial class DataGridViewPaging : UserControl 14 | { 15 | private const int MagicNumber = 10; 16 | private bool _autoHideNavigator; 17 | private bool _computedReadOnly; 18 | private int _currentPageOffset; 19 | private IDbRequestHandler _dbRequestHandler; 20 | private int _maxRecords = 100; 21 | 22 | private int _numberOfRecords; 23 | 24 | private ReadOnlyMode _readonly; 25 | 26 | public DataGridViewPaging() 27 | { 28 | InitializeComponent(); 29 | GridView.AutoGenerateColumns = true; 30 | Disposed += DataGridViewPaging_Disposed; 31 | } 32 | 33 | private bool IsNotPaging => TotalPages == 1 || !HasRows; 34 | 35 | private bool HasRows => _numberOfRecords > 0; 36 | 37 | private bool ComputedReadOnly 38 | { 39 | get => _computedReadOnly; 40 | set 41 | { 42 | _computedReadOnly = value; 43 | PerformLayout(); 44 | } 45 | } 46 | 47 | public IDbRequestHandler DbRequestHandler 48 | { 49 | get => _dbRequestHandler; 50 | set 51 | { 52 | _dbRequestHandler = value; 53 | if (_dbRequestHandler != null) 54 | { 55 | var numberOfRecords = _dbRequestHandler.NumberOfRecords; 56 | Initialize(numberOfRecords); 57 | } 58 | } 59 | } 60 | 61 | private void Initialize(int numberOfRecords) 62 | { 63 | if (numberOfRecords < 0) 64 | throw new QuantityRangeException("Number of records must >= 0."); 65 | _numberOfRecords = numberOfRecords; 66 | _currentPageOffset = 0; 67 | DataSource = null; 68 | QueryData(); 69 | } 70 | 71 | private void QueryData() 72 | { 73 | if (DbRequestHandler != null) 74 | { 75 | if (DataSource is IDisposable disposable) 76 | disposable.Dispose(); 77 | DataSource = DbRequestHandler.DataSource(MaxRecords, _currentPageOffset); 78 | } 79 | } 80 | 81 | private void UpdateNavigatorButtons() 82 | { 83 | if (IsNotPaging) 84 | { 85 | if (_autoHideNavigator && _computedReadOnly) 86 | _navigator.Visible = false; 87 | } 88 | else 89 | { 90 | var totalPages = TotalPages; 91 | var currentPage = CurrentPage; 92 | 93 | bindingNavigatorCountItem.Text = string.Format(_navigator.CountItemFormat, totalPages); 94 | bindingNavigatorPositionItem.Text = currentPage.ToString(); 95 | bindingNavigatorPositionItem.Enabled = totalPages > 1; 96 | 97 | if (currentPage == 1) 98 | { 99 | EnableBack(false); 100 | EnableNext(true); 101 | } 102 | else if (currentPage == totalPages) 103 | { 104 | EnableBack(true); 105 | EnableNext(false); 106 | } 107 | else 108 | { 109 | EnableBack(true); 110 | EnableNext(true); 111 | } 112 | 113 | _navigator.Visible = true; 114 | } 115 | } 116 | 117 | private void EnableNext(bool enabled) 118 | { 119 | bindingNavigatorMoveLastItem.Enabled = enabled; 120 | bindingNavigatorMoveNextItem.Enabled = enabled; 121 | } 122 | 123 | private void EnableBack(bool enabled) 124 | { 125 | bindingNavigatorMoveFirstItem.Enabled = enabled; 126 | bindingNavigatorMovePreviousItem.Enabled = enabled; 127 | } 128 | 129 | private void ComputeReadOnlyIfNecessary() 130 | { 131 | if (DataSource != null && ReadOnly == ReadOnlyMode.Default) ComputedReadOnly = !(DataSource is DataTable); 132 | } 133 | 134 | protected override void OnLayout(LayoutEventArgs e) 135 | { 136 | base.OnLayout(e); 137 | UpdateNavigatorHorizontal(); 138 | } 139 | 140 | private void UpdateNavigatorHorizontal() 141 | { 142 | switch (_navigatorHorizontal) 143 | { 144 | case NavigatorHorizontal.Default: 145 | AlignNavigatorToCenter(); 146 | break; 147 | 148 | case NavigatorHorizontal.Left: 149 | AlignNavigatorToLeft(); 150 | break; 151 | 152 | case NavigatorHorizontal.Center: 153 | AlignNavigatorToCenter(); 154 | break; 155 | 156 | case NavigatorHorizontal.Right: 157 | AlignNavigatorToRight(); 158 | break; 159 | 160 | default: 161 | throw new ArgumentOutOfRangeException(); 162 | } 163 | } 164 | 165 | private void AlignNavigatorToCenter() 166 | { 167 | var totalItemsWidth = 0; 168 | var items = _navigator.Items; 169 | for (var i = 0; i < items.Count; i++) 170 | totalItemsWidth += items[i].Visible ? items[i].Width : 0; 171 | 172 | var containerWidth = _navigator.Width; 173 | var marginLeft = (containerWidth - totalItemsWidth) / 2; 174 | 175 | var firstItem = items[0]; 176 | var firstItemMargin = firstItem.Margin; 177 | firstItemMargin.Left = marginLeft; 178 | firstItem.Margin = firstItemMargin; 179 | } 180 | 181 | private void AlignNavigatorToLeft() 182 | { 183 | var items = _navigator.Items; 184 | var firstItem = items[0]; 185 | var firstItemMargin = firstItem.Margin; 186 | firstItemMargin.Left = 0; 187 | firstItem.Margin = firstItemMargin; 188 | } 189 | 190 | private void AlignNavigatorToRight() 191 | { 192 | var totalItemsWidth = 0; 193 | var items = _navigator.Items; 194 | for (var i = 0; i < items.Count; i++) 195 | totalItemsWidth += items[i].Visible ? items[i].Width : 0; 196 | 197 | var containerWidth = _navigator.Width; 198 | var marginLeft = containerWidth - totalItemsWidth - MagicNumber; 199 | 200 | var firstItem = items[0]; 201 | var firstItemMargin = firstItem.Margin; 202 | firstItemMargin.Left = marginLeft; 203 | firstItem.Margin = firstItemMargin; 204 | } 205 | } 206 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/DataGridViewPaging.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 164, 17 122 | 123 | 124 | 17, 17 125 | 126 | 127 | 128 | 129 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO 130 | wwAADsMBx2+oZAAAASpJREFUOE9jGDygcNbz/00Lnv/PnPj4P1QIA4S3P8Apx5A789n/VUfe/8elKL77 131 | wf/ghmu4DciY8vT/wn0fsCqK73n4f+n+///9qy/gNiCh58n/aVveYyiKaL8P1pw56/9/r9ITuA2I7Hr0 132 | v3f1BxRFoa33wJpb1wFt7/z73yX/AG4DApsf/q+b/w6uKLjl7v9Fe///7wBqzpjz879d3c//9hnbcRvg 133 | UXX/f/60NyiK7Ipv/0+f8/u/f9e3/zqF7/5bJKzHbYB96d3/2ZNfYyjSTzn/36ToxX+VrE//jSOX4TbA 134 | Iu/O/9T+11gVGSSd+C+b9vW/bvA83AYYZt3+H9byEqci/dTL/zV8p+E2QCftxn+/6od4Fal4TMBtgFPu 135 | lf8gBXgVDULAwAAA8HbAq6XlmnAAAAAASUVORK5CYII= 136 | 137 | 138 | 139 | 140 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO 141 | wwAADsMBx2+oZAAAALZJREFUOE9jGDogvP3BfyiTdBDf/eB/cMM18gyI73n4f+n+///9qy+QbkBE+32w 142 | 5sxZ//97lZ4gzYDQ1ntgza3rgLZ3/v3vkn+AeAOCW+7+X7T3//8OoOaMOT//29X9/G+fsZ00F9gV3/6f 143 | Puf3f/+ub/91Ct/9t0hYT3oY6Kec/29S9OK/Stan/8aRy0g3AAQMkk78l037+l83eB55BoCAfurl/xq+ 144 | 08g3AARUPCZQZsBgBQwMANAUYJgEulBVAAAAAElFTkSuQmCC 145 | 146 | 147 | 148 | 149 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO 150 | wwAADsMBx2+oZAAAAKNJREFUOE9jGHygcNbz/1AmeSB35rP/Cd33yDckY8rT//P2//6f0HWHPEMSep78 151 | n73v1//OrX//u5VeJt2QyK5H/6ds+/W/ZOnf/wnT//63yT1LmiGBzQ//t659D9ZsXPLlv3T0tf/GkcuI 152 | N8Sj6v7/krnv4JoVXXpIc4F96d3/gS3PyNMMAhZ5d/7bFFwhTzMIGGbdJl8zCOik3SBf81AEDAwAoH5f 153 | oAc0QjgAAAAASUVORK5CYII= 154 | 155 | 156 | 157 | 158 | iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAO 159 | wwAADsMBx2+oZAAAASxJREFUOE9jGFygcNbz/1AmBgDJNS14/j9z4mOcahhyZz77n9B9D6sCkNyqI+// 160 | h7c/wG1AxpSn/+ft//0/oesOhiKQ3MJ9H/4HN1zDbUBCz5P/s/f9+t+59e9/t9LLKApBctO2vP/vX30B 161 | twGRXY/+T9n263/J0r//E6b//W+TexauGCTXu/rDf6/SE7gNCGx++L917XuwZuOSL/+lo6/9N45cBtYA 162 | kqub/+6/S/4B3AZ4VN3/XzL3HVyzoksPXDFILn/am//2GdtxG2Bfevd/YMszDM0gAJLLnvz6v0XCetwG 163 | WOTd+W9TcAVDMwiA5FL7X8O9hBUYZt3GqhkEQHJhLS//6wbPw22ATtoNnJIgOb/qh/81fKfhNgAfcMq9 164 | 8l/FYwIYQ4UGBWBgAAC+0b+zuQxOnAAAAABJRU5ErkJggg== 165 | 166 | 167 | -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/DbRequestHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Data.Common; 4 | using Code4Bugs.SimpleDataGridViewPaging.Statement; 5 | using Code4Bugs.SimpleDataGridViewPaging.Statement.Builder; 6 | 7 | namespace Code4Bugs.SimpleDataGridViewPaging 8 | { 9 | public class DbRequestHandler : IDbRequestHandler 10 | { 11 | private Helper _countHelper; 12 | private bool _disposed; 13 | private bool _initialized; 14 | private int _numberOfRecords = -1; 15 | private Helper _rowsHelper; 16 | private bool _shouldCloseConnection; 17 | 18 | public DbConnection Connection { get; set; } 19 | public string TableName { get; set; } 20 | public CountStatementBuilder CountStatementBuilder { get; set; } 21 | public RowsStatementBuilder RowsStatementBuilder { get; set; } 22 | 23 | public int NumberOfRecords => _numberOfRecords < 0 24 | ? _numberOfRecords = QueryNumberOfRecords() 25 | : _numberOfRecords; 26 | 27 | public virtual object DataSource(int maxRecords, int pageOffset) 28 | { 29 | InitializeIfNecessary(); 30 | 31 | _rowsHelper.StatementBuilder = RowsStatementBuilder 32 | .MaxRecords(maxRecords) 33 | .PageOffset(pageOffset); 34 | 35 | return _rowsHelper 36 | .Build() 37 | .Execute(); 38 | } 39 | 40 | public void Dispose() 41 | { 42 | Disposing(true); 43 | GC.SuppressFinalize(this); 44 | } 45 | 46 | ~DbRequestHandler() 47 | { 48 | Disposing(false); 49 | } 50 | 51 | private int QueryNumberOfRecords() 52 | { 53 | InitializeIfNecessary(); 54 | 55 | return _countHelper 56 | .Build() 57 | .Execute(); 58 | } 59 | 60 | private void InitializeIfNecessary() 61 | { 62 | if (!_initialized) 63 | { 64 | if (CountStatementBuilder == null) 65 | CountStatementBuilder = new CountStatementBuilder(); 66 | 67 | _countHelper = new Helper 68 | { 69 | StatementBuilder = CountStatementBuilder, 70 | TableName = TableName, 71 | Connection = Connection 72 | }; 73 | 74 | if (RowsStatementBuilder == null) 75 | RowsStatementBuilder = new RowsStatementBuilder(); 76 | 77 | _rowsHelper = new Helper 78 | { 79 | StatementBuilder = RowsStatementBuilder, 80 | TableName = TableName, 81 | Connection = Connection 82 | }; 83 | 84 | if (Connection != null && Connection.State == ConnectionState.Closed) 85 | { 86 | Connection.Open(); 87 | _shouldCloseConnection = true; 88 | } 89 | 90 | _initialized = true; 91 | } 92 | } 93 | 94 | protected virtual void Disposing(bool disposing) 95 | { 96 | if (!_disposed) 97 | lock (this) 98 | { 99 | _countHelper?.Dispose(); 100 | _rowsHelper?.Dispose(); 101 | if (Connection != null && _shouldCloseConnection) 102 | Connection.Close(); 103 | _disposed = true; 104 | } 105 | } 106 | 107 | private class Helper : IDisposable 108 | { 109 | private IStatement _previousStatement; 110 | 111 | public StatementBuilder StatementBuilder { get; set; } 112 | public string TableName { get; set; } 113 | public DbConnection Connection { get; set; } 114 | 115 | public void Dispose() 116 | { 117 | DisposeStatement(); 118 | if (StatementBuilder is IDisposable disposable) 119 | disposable.Dispose(); 120 | } 121 | 122 | public IStatement Build() 123 | { 124 | DisposeStatement(); 125 | 126 | _previousStatement = StatementBuilder 127 | .TableName(TableName) 128 | .Connection(Connection) 129 | .Build(); 130 | 131 | return _previousStatement; 132 | } 133 | 134 | private void DisposeStatement() 135 | { 136 | if (_previousStatement is IDisposable disposable) 137 | disposable.Dispose(); 138 | } 139 | } 140 | } 141 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/DbRequestHandlerHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | using System.Data.SqlClient; 3 | using Code4Bugs.SimpleDataGridViewPaging.Statement.Builder; 4 | 5 | namespace Code4Bugs.SimpleDataGridViewPaging 6 | { 7 | public static class DbRequestHandlerHelper 8 | { 9 | private static readonly string SqlServerSelectCommandText = "SELECT * FROM {0} ORDER BY (SELECT NULL) OFFSET {2} ROWS FETCH NEXT {1} ROWS ONLY"; 10 | 11 | public static IDbRequestHandler Create(DbConnection connection, string tableName) 12 | { 13 | var statementBuilder = connection.GetType() == typeof(SqlConnection) 14 | ? new RowsStatementBuilder().CommandText(SqlServerSelectCommandText) as RowsStatementBuilder 15 | : null; 16 | 17 | return new DbRequestHandler 18 | { 19 | Connection = connection, 20 | TableName = tableName, 21 | RowsStatementBuilder = statementBuilder 22 | }; 23 | } 24 | 25 | public static IDbRequestHandler Create( 26 | DbConnection connection, 27 | string tableName, 28 | DbCommandBuilder commandBuilder) 29 | { 30 | var statementBuilder = new UpdatableRowsStatementBuilder().CommandBuilder(commandBuilder); 31 | if (connection.GetType() == typeof(SqlConnection)) 32 | statementBuilder.CommandText(SqlServerSelectCommandText); 33 | 34 | return new DbRequestHandler 35 | { 36 | Connection = connection, 37 | TableName = tableName, 38 | RowsStatementBuilder = statementBuilder 39 | }; 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/Exceptions/QuantityRangeException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Code4Bugs.SimpleDataGridViewPaging.Exceptions 4 | { 5 | public class QuantityRangeException : Exception 6 | { 7 | public QuantityRangeException() 8 | { 9 | } 10 | 11 | public QuantityRangeException(string message) : base(message) 12 | { 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/IDbRequestHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Code4Bugs.SimpleDataGridViewPaging 4 | { 5 | /// 6 | /// 7 | /// Manages querying data from the database. 8 | /// 9 | public interface IDbRequestHandler : IDisposable 10 | { 11 | int NumberOfRecords { get; } 12 | 13 | object DataSource(int maxRecords, int pageOffset); 14 | } 15 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/NavigatorHorizontal.cs: -------------------------------------------------------------------------------- 1 | namespace Code4Bugs.SimpleDataGridViewPaging 2 | { 3 | public enum NavigatorHorizontal 4 | { 5 | Default, 6 | Left, 7 | Center, 8 | Right 9 | } 10 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | 4 | // General Information about an assembly is controlled through the following 5 | // set of attributes. Change these attribute values to modify the information 6 | // associated with an assembly. 7 | [assembly: AssemblyTitle("SimpleDataGridViewPaging")] 8 | [assembly: AssemblyDescription("A simple UserControl that shows the data-table and paging automatically.")] 9 | [assembly: AssemblyConfiguration("")] 10 | [assembly: AssemblyCompany("www.code4bugs.com")] 11 | [assembly: AssemblyProduct("SimpleDataGridViewPaging")] 12 | [assembly: AssemblyCopyright("Copyright © 2018")] 13 | [assembly: AssemblyTrademark("")] 14 | [assembly: AssemblyCulture("")] 15 | 16 | // Setting ComVisible to false makes the types in this assembly not visible 17 | // to COM components. If you need to access a type in this assembly from 18 | // COM, set the ComVisible attribute to true on that type. 19 | [assembly: ComVisible(false)] 20 | 21 | // The following GUID is for the ID of the typelib if this project is exposed to COM 22 | [assembly: Guid("8784a91a-10e1-4f2d-a233-eaf60275f2f0")] 23 | 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the values or you can default the Build and Revision Numbers 32 | // by using the '*' as shown below: 33 | // [assembly: AssemblyVersion("1.0.*")] 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/ReadOnlyMode.cs: -------------------------------------------------------------------------------- 1 | namespace Code4Bugs.SimpleDataGridViewPaging 2 | { 3 | public enum ReadOnlyMode 4 | { 5 | /// 6 | /// The read-only mode will be caculated by the DataSource. 7 | /// 8 | Default, 9 | True, 10 | False 11 | } 12 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/SimpleDataGridViewPaging.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {8784A91A-10E1-4F2D-A233-EAF60275F2F0} 8 | Library 9 | Properties 10 | Code4Bugs.SimpleDataGridViewPaging 11 | SimpleDataGridViewPaging 12 | v4.5 13 | 512 14 | 15 | 16 | true 17 | full 18 | false 19 | bin\Debug\ 20 | TRACE;DEBUG 21 | prompt 22 | 4 23 | 24 | 25 | pdbonly 26 | true 27 | bin\Release\ 28 | TRACE 29 | prompt 30 | 4 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | UserControl 41 | 42 | 43 | DataGridViewPaging.cs 44 | 45 | 46 | UserControl 47 | 48 | 49 | UserControl 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | DataGridViewPaging.cs 70 | Designer 71 | 72 | 73 | 74 | 81 | -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/Statement/AdapterStatement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | using System.Data.Common; 4 | 5 | namespace Code4Bugs.SimpleDataGridViewPaging.Statement 6 | { 7 | /// 8 | /// 9 | /// The statement supports the update capability. 10 | /// 11 | public class AdapterStatement : IStatement, IDisposable 12 | { 13 | private readonly DbDataAdapter _adapter; 14 | private readonly DbCommandBuilder _commandBuilder; 15 | private DataTable _dataTable; 16 | 17 | public AdapterStatement(DbCommand selectCommand, DbCommandBuilder commandBuilder) 18 | { 19 | _commandBuilder = commandBuilder; 20 | _adapter = commandBuilder.DataAdapter; 21 | _adapter.SelectCommand = selectCommand; 22 | _adapter.UpdateCommand = commandBuilder.GetUpdateCommand(); 23 | _adapter.InsertCommand = commandBuilder.GetInsertCommand(); 24 | _adapter.DeleteCommand = commandBuilder.GetDeleteCommand(); 25 | } 26 | 27 | public void Dispose() 28 | { 29 | DisposeTableIfNecessary(); 30 | } 31 | 32 | public virtual DataTable Execute() 33 | { 34 | DisposeTableIfNecessary(); 35 | _dataTable = new DataTable(); 36 | _adapter.Fill(_dataTable); 37 | return _dataTable; 38 | } 39 | 40 | private void DisposeTableIfNecessary() 41 | { 42 | if (_dataTable != null) 43 | { 44 | _adapter.Update(_dataTable); 45 | _dataTable.Dispose(); 46 | } 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/Statement/Builder/CountStatementBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace Code4Bugs.SimpleDataGridViewPaging.Statement.Builder 2 | { 3 | /// 4 | /// Queries number of records of the table. 5 | /// 6 | public class CountStatementBuilder : StatementBuilder 7 | { 8 | public override IStatement Build() 9 | { 10 | var commandText = string.IsNullOrEmpty(_commandText) 11 | ? $"SELECT COUNT(*) FROM {_tableName}" 12 | : _commandText; 13 | return new ScalarStatement(_connection, commandText); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/Statement/Builder/RowsStatementBuilder.cs: -------------------------------------------------------------------------------- 1 | namespace Code4Bugs.SimpleDataGridViewPaging.Statement.Builder 2 | { 3 | /// 4 | /// Queries data rows of the table. 5 | /// 6 | public class RowsStatementBuilder : StatementBuilder 7 | { 8 | protected int _maxRecords; 9 | protected int _pageOffset; 10 | 11 | public RowsStatementBuilder MaxRecords(int maxRecords) 12 | { 13 | _maxRecords = maxRecords; 14 | return this; 15 | } 16 | 17 | public RowsStatementBuilder PageOffset(int pageOffset) 18 | { 19 | _pageOffset = pageOffset; 20 | return this; 21 | } 22 | 23 | protected string GetCommandText() 24 | { 25 | return string.IsNullOrEmpty(_commandText) 26 | ? $"SELECT * FROM {_tableName} LIMIT {_maxRecords} OFFSET {_pageOffset}" 27 | : string.Format(_commandText, _tableName, _maxRecords, _pageOffset); 28 | } 29 | 30 | public override IStatement Build() 31 | { 32 | return new ReaderStatement(_connection, GetCommandText()); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/Statement/Builder/StatementBuilder.cs: -------------------------------------------------------------------------------- 1 | using System.Data.Common; 2 | 3 | namespace Code4Bugs.SimpleDataGridViewPaging.Statement.Builder 4 | { 5 | /// 6 | /// Builds a . 7 | /// 8 | /// Return type of 9 | public abstract class StatementBuilder 10 | { 11 | protected string _commandText; 12 | protected DbConnection _connection; 13 | protected string _tableName; 14 | 15 | public StatementBuilder Connection(DbConnection connection) 16 | { 17 | _connection = connection; 18 | return this; 19 | } 20 | 21 | public StatementBuilder TableName(string tableName) 22 | { 23 | _tableName = tableName; 24 | return this; 25 | } 26 | 27 | public StatementBuilder CommandText(string commandText) 28 | { 29 | _commandText = commandText; 30 | return this; 31 | } 32 | 33 | public abstract IStatement Build(); 34 | } 35 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/Statement/Builder/UpdatableRowsStatementBuilder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data.Common; 3 | 4 | namespace Code4Bugs.SimpleDataGridViewPaging.Statement.Builder 5 | { 6 | /// 7 | /// 8 | /// This supports updatable mode, the user needs to pass one more parameter is . 9 | /// 10 | public class UpdatableRowsStatementBuilder : RowsStatementBuilder, IDisposable 11 | { 12 | private DbCommandBuilder _commandBuilder; 13 | 14 | public void Dispose() 15 | { 16 | if (_commandBuilder != null) 17 | { 18 | _commandBuilder.Dispose(); 19 | _commandBuilder.DataAdapter?.Dispose(); 20 | } 21 | } 22 | 23 | public UpdatableRowsStatementBuilder CommandBuilder(DbCommandBuilder commandBuilder) 24 | { 25 | _commandBuilder = commandBuilder; 26 | return this; 27 | } 28 | 29 | public override IStatement Build() 30 | { 31 | var command = _connection.CreateCommand(); 32 | command.CommandText = GetCommandText(); 33 | return new AdapterStatement(command, _commandBuilder); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/Statement/IStatement.cs: -------------------------------------------------------------------------------- 1 | namespace Code4Bugs.SimpleDataGridViewPaging.Statement 2 | { 3 | public interface IStatement 4 | { 5 | T Execute(); 6 | } 7 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/Statement/ReaderStatement.cs: -------------------------------------------------------------------------------- 1 | using System.Data; 2 | 3 | namespace Code4Bugs.SimpleDataGridViewPaging.Statement 4 | { 5 | public class ReaderStatement : IStatement 6 | { 7 | private readonly string _commandText; 8 | private readonly IDbConnection _connection; 9 | 10 | public ReaderStatement(IDbConnection connection, string commandText) 11 | { 12 | _connection = connection; 13 | _commandText = commandText; 14 | } 15 | 16 | public object Execute() 17 | { 18 | using (var command = _connection.CreateCommand()) 19 | { 20 | command.CommandText = _commandText; 21 | return command.ExecuteReader(); 22 | } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /SimpleDataGridViewPaging/Statement/ScalarStatement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Data; 3 | 4 | namespace Code4Bugs.SimpleDataGridViewPaging.Statement 5 | { 6 | public class ScalarStatement : IStatement 7 | { 8 | private readonly string _commandText; 9 | private readonly IDbConnection _connection; 10 | 11 | public ScalarStatement(IDbConnection connection, string commandText) 12 | { 13 | _connection = connection; 14 | _commandText = commandText; 15 | } 16 | 17 | public int Execute() 18 | { 19 | using (var command = _connection.CreateCommand()) 20 | { 21 | command.CommandText = _commandText; 22 | var result = command.ExecuteScalar(); 23 | return Convert.ToInt32(result); 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /nuget/SimpleDataGridViewPaging.1.0.0.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sontx/simple-datagridview-paging/e78458ec5537c03aeb6409da555b98ffd90edc4e/nuget/SimpleDataGridViewPaging.1.0.0.nupkg -------------------------------------------------------------------------------- /nuget/SimpleDataGridViewPaging.2.0.0.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sontx/simple-datagridview-paging/e78458ec5537c03aeb6409da555b98ffd90edc4e/nuget/SimpleDataGridViewPaging.2.0.0.nupkg -------------------------------------------------------------------------------- /nuget/SimpleDataGridViewPaging.2.0.1.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sontx/simple-datagridview-paging/e78458ec5537c03aeb6409da555b98ffd90edc4e/nuget/SimpleDataGridViewPaging.2.0.1.nupkg -------------------------------------------------------------------------------- /nuget/SimpleDataGridViewPaging.2.0.2.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sontx/simple-datagridview-paging/e78458ec5537c03aeb6409da555b98ffd90edc4e/nuget/SimpleDataGridViewPaging.2.0.2.nupkg --------------------------------------------------------------------------------