I am developing an application with Winforms, and have gone down the path of data binding my grids using a BindingSource
. My question is:
Is this the best approach to take? Should I manually populate the cells instead of letting the BindingSource
do it for me? Could it lead to problems further down the track? If there are any situations where data binding would create issues, that would be useful.
One of my colleagues swears black and blue NOT to use databinding. I don't really trust what he says, so any pros/cons would be valuable.
In the situation of a multi-user application connecting to a single database and editable DataGrid
s, how would you solve concurrency issues for updating of data?
Simple data binding is the type of binding typical for controls such as a TextBox control or Label control, which are controls that typically only display a single value. In fact, any property on a control can be bound to a field in a database. There's extensive support for this feature in Visual Studio.
Data binding is the process that establishes a connection between the app UI and the data it displays. If the binding has the correct settings and the data provides the proper notifications, when the data changes its value, the elements that are bound to the data reflect changes automatically.
Companies are still using Windows Forms because it allows communication with Windows on a lower level than a web application. WPF also allows greater data binding and has easier tools to handle complex tasks.
In this article, we perform CRUD Operations in a Windows Form application. For this CRUD operation, we are using Entity framework. We perform all operations like create, update, delete and select using the entity framework.
Swearing black and blue about anything without giving reasons why is, frankly, dumb.
There are scenarios where data-binding is great, and scenarios where it is more trouble than it is worth. Your colleague isn't doing you any favors if only reporting from the "pain" end of the spectrum.
For simple display of data, great! It'll save you lots of time and errors. For direct updates of data (including property logic and IDataErrorInfo
support), again, great!. And indeed it is a core part of WPF etc.
There are scenarios where it isn't so helpful:
I would ask your colleague "why"; and if they can't give a good reason, I'd be inclined to ignore them. Without a sensible discussion behind it is just FUD.
I personally find that using the data binding process which is much easier for programming, you don't have to do the iteration, and overall reduces LOC.
From Data binding concepts in .NET windows forms:
Advantages of DataBinding
Databinding in .NET can be used to write data driven applications quickly. .NET data binding allows you to write less code with fast execution but still get the work done in the best way.
.NET automatically writes a lot of databinding code for you in the background (you can see it in "Windows Generated Code" section), so the developer does not have to spend time writing code for basic databinding, but still has the flexibility of modifying any code that he would like to. We get the benefits of bound as well as unbound approach.
Control over the Databinding process by using events. This is discussed in more detail later in the article.
Disadvantages of DataBinding
More optimized code can be written by using the unbound or traditional methods.
Complete flexibility can only be achieved by using the unbound approach.
Fore more clarification you should see Data binding concepts in .NET windows forms
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With