Josh-CO Dev

Solving the worlds problems one line of code at a time.

.NET – 2 way databinding via a binding source

Leave a comment

One thing that I have always loved about Delphi is how well all the controls play together and the flexibility that you have through the visual designer. Data binding to controls is a cinch. You can drop in a query object and then tie it to a dataset. You can then bind anything to this dataset, such as a grid and several drop downs. When you click on a row, it will show the value in the corresponding drop down boxes as well.

In .NET, this is much harder to accomplish using an N-Tier framework. I discovered the other day that when using binding sources you can accomplish this by using just one extra line of code:

textBox.DataBindings.Add(new Binding("Text", BindingSource, "Field_name", true));

Piece of cake! Now when any other object that is bound to this dataset is selected, generally a grid, the text in the textbox will update to the contents of the dataset.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s