none
DataSource vs DataBindingSource???

    Question

  • I'm a bit confused about these two. What is the difference and in what
    circumstances would you use one or the other or both?

    Thanks
    Wednesday, November 05, 2008 8:25 PM

Answers

  • I presume that you mean BindingSource, not DataBindingSource.

    DataSource is a property of controls that support "complex" binding (complex binding is binding to a list, such as in a grid where each list item becomes a row in the grid).  In theory, the DataSource property can be set to many different kinds of list.  In practice, the following configuration is most common:

    DataSource property:  Set to the DataSet.
    DataMember property:  Set to the name of a DataTable in the DataSet.

    In .NET 2.0, the BindingSource class was introduced.  When using the Visual Studio designer, you can drag it onto a Form from the toolbox.  The BindingSource provides an extra level of indirection between the complex-bound control and the underlying data source (e.g., the DataSet).  The BindingSource provides methods for keeping track of the "current" item (such as the item corresponding to the row that is currently active in a bound grid).  It is possible to do this without BindingSource, but BindingSource makes it easier to determine the "current" item and change which item is considered "current".  The relevant properties are BindingSource.Position and BindingSource.Current.  The BindingSource is typically used as follows:

    BindingSource:

    DataSource property:  Set to the DataSet.
    DataMember property:  Set to the name of a DataTable in the DataSet.

    Complex-Bound Control (such as a DataGridView):

    DataSource property:  Set to the BindingSource you configured above.
    DataMember property:  Leave as empty string.

    Due to the BindingSource's advantages, I always recommend going through a BindingSource.  Also, the Visual Studio designer is set up in a way that encourages this design as BindingSources appear most prominently when you drop down on a DataSource property in the property grid.
    • Proposed as answer by Guo Surfer Friday, November 07, 2008 8:11 AM
    • Marked as answer by Guo Surfer Tuesday, November 11, 2008 8:33 AM
    Thursday, November 06, 2008 12:58 AM

All replies

  • I presume that you mean BindingSource, not DataBindingSource.

    DataSource is a property of controls that support "complex" binding (complex binding is binding to a list, such as in a grid where each list item becomes a row in the grid).  In theory, the DataSource property can be set to many different kinds of list.  In practice, the following configuration is most common:

    DataSource property:  Set to the DataSet.
    DataMember property:  Set to the name of a DataTable in the DataSet.

    In .NET 2.0, the BindingSource class was introduced.  When using the Visual Studio designer, you can drag it onto a Form from the toolbox.  The BindingSource provides an extra level of indirection between the complex-bound control and the underlying data source (e.g., the DataSet).  The BindingSource provides methods for keeping track of the "current" item (such as the item corresponding to the row that is currently active in a bound grid).  It is possible to do this without BindingSource, but BindingSource makes it easier to determine the "current" item and change which item is considered "current".  The relevant properties are BindingSource.Position and BindingSource.Current.  The BindingSource is typically used as follows:

    BindingSource:

    DataSource property:  Set to the DataSet.
    DataMember property:  Set to the name of a DataTable in the DataSet.

    Complex-Bound Control (such as a DataGridView):

    DataSource property:  Set to the BindingSource you configured above.
    DataMember property:  Leave as empty string.

    Due to the BindingSource's advantages, I always recommend going through a BindingSource.  Also, the Visual Studio designer is set up in a way that encourages this design as BindingSources appear most prominently when you drop down on a DataSource property in the property grid.
    • Proposed as answer by Guo Surfer Friday, November 07, 2008 8:11 AM
    • Marked as answer by Guo Surfer Tuesday, November 11, 2008 8:33 AM
    Thursday, November 06, 2008 12:58 AM
  • Binary Coder: thank you.

    I have seen a BindingSource described as an intermediary between a collection (data source) and a grid or list control and providing an extra layer of abstraction. Your explanation clarifies this.
    Thursday, November 06, 2008 3:12 AM