Binding Source

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

Hello All,

I am teaching myself C#. The book I am using has the following example
using a BindingSource object. Here is the code.

NorthwindDataSetTableAdapters.ProductsTableAdapter productsTA = new
ProductsMaintenance.NorthwindDataSetTableAdapters.ProductsTableAdapter();
productsTA.Fill(northwindDataSet.Products);
BindingSource productsBS = new BindingSource(northwindDataSet,
"Products");
productsGrid.DataSource = productsBS;

This code works and I am not having now trouble understanding why it
works. What I don't understand is why I need a BindingSource object at
all. The following code seems to work just as well without using a
BindingSource object.

NorthwindDataSetTableAdapters.ProductsTableAdapter productsTA = new
ProductsMaintenance.NorthwindDataSetTableAdapters.ProductsTableAdapter();
productsTA.Fill(northwindDataSet.Products);
productsGrid.DataSource = northwindDataSet.Products;

Am I missing something? Perhaps these two blocks of code do not produce
exactly the same results.

Help is always apprecated. Thank you.

Paul
 
Hi Paul,

BindingSource, new to the 2.0 framework, is used by the designers to bind
your data source to a control. BindingSource provides support for binding
to things other than just IBindingList implementations and DataSets. For
instance, you can use it to bind to a collection of business objects and it
will reflect into the properties of your objects as if they were columns of
a DataRow.

In this particular example, I don't think it's adding any particularly
useful features, however, the designers in VS 2005 support binding to a
BindingSource for everything so it's a good habit to get into, but it's not
always necessary.

Lots of good stuff here:

BindingSource Component
http://msdn2.microsoft.com/en-us/library/h974h4y2.aspx
 
Here are a few advantages of using a BindingSource:

You can sort, search, and filter on the underlying data source.

It gives you the item currently displayed from the data source.

It exposes properties and methods to change the current item
programmatically.

It exposes events for changes in the data source.

Robin S.
-------------------------------
 
Back
Top