The BindingSource component serves two purposes. First, it simplifies binding controls on a form to data by providing a layer of indirection, currency management, change notification, and other services. This is accomplished by attaching the BindingSource component to your data source, and then binding the controls on your form to the BindingSource component. All further interaction with the data, including navigating, sorting, filtering, and updating, is accomplished with calls to the BindingSource component.
Second, the BindingSource component can act as a strongly typed data source. Typically the type of the underlying data source is fixed through one of the following mechanisms:
-
Use the Add method to add an item to the BindingSource component.
-
Set the DataSource property to a list, single object, or type.
Both of these mechanisms create a strongly-typed list. BindingSource supports both simple and complex data binding as indicated by its DataSource and DataMember properties.
Note |
|---|
| Because a BindingSource handles both simple and complex data sources, terminology is problematic. Within this class documentation, the term list refers to a data collection within the hosted data source, and item denotes a single element. When discussing functionality associated with complex data sources, the equivalent terms table and row are used. |
BindingSource provides members for accessing the underlying data. The current item can be retrieved through the Current property, and the entire list can be retrieved through the List property. Editing operations are supported on the current item through Current and the RemoveCurrent, EndEdit, CancelEdit and Add and AddNew methods. Although currency management is handled automatically for all underlying data source types, this class exposes a number of events, such as CurrentItemChanged and DataSourceChanged, that allow for customization.
Data sources that are bound to a BindingSource component can also be navigated and managed with the BindingNavigator class, which provides a VCR-like user interface (UI) for navigating items within a list. Although BindingNavigator can be bound to any data source, it was designed to integrate with a BindingSource component through its BindingNavigator.BindingSource property.
The default property for the BindingSource class is DataSource. The default event is CurrentChanged.
Caution |
|---|
| Many of the members of the BindingSource class operate on the underlying list represented by the List property and simply refer their operation to the underlying list. Therefore, when the BindingSource is bound to a custom implementation of IList, the exact behavior of these members may differ from the behavior described in the class documentation. For example, the RemoveAt method calls IList.RemoveAt. The BindingSource documentation describes the RemoveAt method with the understanding that the RemoveAt method for the underlying IList is correctly implemented. |