BindingSource Component Overview
The BindingSource component is designed to simplify the process of binding controls to an underlying data source. The BindingSource component acts as both a conduit and a data source for other controls to bind to. It provides an abstraction of your form's data connection while passing through commands to the underlying list of data. Additionally, you can add data directly to it, so that the component itself functions as a data source.
The BindingSource component acts as the data source for some or all of the controls on the form. In Visual Studio, the BindingSource can be bound to a control by means of the DataBindings property, which is accessible from the Properties window. For more information, see How to: Bind Windows Forms Controls with the BindingSource Component Using the Designer and How to: Bind Windows Forms Controls with the BindingSource Component Using the Designer and How to: Bind Windows Forms Controls with the BindingSource Component Using the Designer and How to: Bind Windows Forms Controls with the BindingSource Component Using the Designer.
You can bind the BindingSource component to both simple data sources, like a single property of an object or a basic collection like ArrayList, and complex data sources, like a database table. The BindingSource component acts as an intermediary that provides binding and currency management services. At design time or run time, you can bind a BindingSource component to a complex data source by setting its DataSource and DataMember properties to the database and table, respectively. The following illustration demonstrates where the BindingSource component fits into the existing data-binding architecture.
At design time, some actions, like dragging a database table from a data window onto a blank form, will create the BindingSource component, bind it to the underlying data source, and add data-aware controls all in one operation. For more information, see Displaying Data Overview and Displaying Data Overview and Binding Windows Forms Controls to Data in Visual Studio and Binding Windows Forms Controls to Data in Visual Studio and Binding Windows Forms Controls to Data in Visual Studio.
If you start adding items to the BindingSource component without first specifying a list to be bound to, the component will act like a list-style data source and accept these added items.
Additionally, you can write code to provide custom "AddNew" functionality by means of the AddingNew event, which is raised when the AddNew method is called prior to the item being added to the list. For more information, see BindingSource Component Architecture.
The: BindingSource acts as a CurrencyManager for all of its bindings and can, therefore, provide access to currency and position information regarding the data source. The following table shows the members that the BindingSource component provides for accessing and manipulating the underlying data.
Gets the current item of the data source.
Gets or sets the current position in the underlying list.
Inserts an item in the list at the specified index.
Removes the current item from the list.
Applies pending changes to the underlying data source.
Cancels the current edit operation.
Adds a new item to the underlying list. If the data source implements IBindingList and returns an item from the AddingNew event, adds this item. Otherwise, the request is passed to the list's AddNew method. If the underlying list is not an IBindingList, the item is automatically created through its public default constructor.
Usually, you should work with an ordered or filtered view of the data source. The following table shows the members that the BindingSource component data source provides.
If the data source is an IBindingList, gets or sets a column name used for sorting and sort order information. If the data source is an IBindingListView and supports advanced sorting, gets multiple column names used for sorting and sort order information
If the data source is an IBindingListView, gets or sets the expression used to filter which rows are viewed.