This is a walkthrough on using databinding in winforms and EF. It will guide you through setting up databinding and entity frameowork to allow data to be read and modified with very little code.
-
Create a new VB Winforms Project -- https://github.com/VBDev2Dev/DataBinding/commit/68779b3a8d51402371d36b0b979f69aa373c135d
-
Add class or classes that model your data -- https://github.com/VBDev2Dev/DataBinding/commit/77b92b9d5343bced53fd9d2fb7a22296c09b2c1e
- Hit Ctrl + Shift + B to build project.
-
Add a bound DataGridView to form -- https://github.com/VBDev2Dev/DataBinding/commit/ac7b15965d4d32672439c793b33b90646b568c00
-
Add code to bind the BindingSource to the data -- https://github.com/VBDev2Dev/DataBinding/commit/df5006ff5b48ff4b745a720f38e9c8c6071350c9
-
Add a temporary button that will let you see the data has been updated.
-
Add a button
-
In click event add this code:
MessageBox.Show($"You have {data.Count} items in the list. The total of all C values is {data.Sum(function(r) r.C)}.")
-
-
Debug the project
- Add some rows in grid
- Click button.
-
Add DB items to project
-
Add Service Based Database. -- https://github.com/VBDev2Dev/DataBinding/commit/c035ce0b32bafeba0bb3cfeae4af943712564e6c This adds an empty sql server database that you can modify if needed
-
Add EF Database Context -- https://github.com/VBDev2Dev/DataBinding/commit/4c7be23160b0a64244fccaa67c0c40d62f5fd606
-
Adjust connection string of context to use DataDirectory Note that several ADO .net providers support this. Read the linked forum discussion to learn all about DataDirectory and how to set it. You will need to do so if you deploy the program and use a different folder than where the exe resides. -- https://github.com/VBDev2Dev/DataBinding/commit/46d5ef4b747f59e7a6d44466c6c8e662f9d555b4
-
Enable Migrations This makes it so you are deliberate with your migrations. -- https://github.com/VBDev2Dev/DataBinding/commit/2fc00db8e0663a6a9110c2996e0cfa0e245520a8
Enable-Migrations -
Run Add-Migration and Update-Database -- https://github.com/VBDev2Dev/DataBinding/commit/717f17eb919a874b04a0bf188d4b3e1e896b0bae
Add-Migration "Increase length of name" Update-Database
-
Set database Copy to Output Directory property to Copy if newer This prevents builds from copying the database every time. This is needed if you want to add another migration. -- https://github.com/VBDev2Dev/DataBinding/commit/54581d486f79eb8cc5d03d7179b47fc3c3675c20
-
Add a migration to change the length of the Name column Add-Migration and Update-Database -- https://github.com/VBDev2Dev/DataBinding/commit/2211fe3645e10e687a852689ef8c2fb9fa8d284e
Add-Migration "Increase length of name" Update-Database
-
Seed db with initial data -- https://github.com/VBDev2Dev/DataBinding/commit/613b45b60c15a78b4ae80744863f53c494fa8c10
Update-Database -
Load data from db into context and show in grid -- https://github.com/VBDev2Dev/DataBinding/commit/e35c01ffb31207986e6357f56be700c1086cfd81
-
Save changes to db -- https://github.com/VBDev2Dev/DataBinding/commit/aefe5fba1d8e1da7cc116d3b780d35af2bc7b43b
-
Sort data coming from db -- https://github.com/VBDev2Dev/DataBinding/commit/8928f0daceb4767389cf008708c07be7d9423b7a
-
-
Make grid repsonsive -- https://github.com/VBDev2Dev/DataBinding/commit/409e37078c528e4ae093a1e321bf19d6dab42832
-
Add logging -- https://github.com/VBDev2Dev/DataBinding/commit/fa2a49131ad3bc702e93b5736d53d644b472cc14
Install-Package Serilog.Sinks.File Install-Package Serilog.Sinks.Console











