Introduction
Data binding provides a simple, convenient, powerful, and transparent way
for developers to create a read/write link between the controls on a form
and the data in their application (their data model).
Windows Forms supports binding data to ADO.NET DataSet controls, Array controls,
ArrayList controls, and
so on. A control can be bound to any collection that supports indexed
access to the elements in that collection -- to be specific, to any
collection that implements the IList interface.
Simple Data Binding
Simple data binding means binding a single value within the
data model to a single property of a control. For example, binding
TextBox1.Text to Customer.Name. Simple binding is managed by use of the
Bindings collection on each control.
Complex Data Binding
Complex data binding means binding a control to a collection (rather than binding a control to
a single item within the collection). For example, the DataGrid has a
DataSource property that can be set to an entire DataSet or Array. The
DataGrid extracts information from the DataSource and
displays it. ListBox and ComboBox also use complex data binding.
One-Way and Two-Way Data Binding
One-way data binding describes a process by which a property of a control is bound to the
data model for read-only or presentation purposes. When data binding is
set up in this fashion, the property reflects the value of the data,
but direct changes to the property are not reflected in the data model.
Two-way data binding describes a process by which a property of a control is bound to the
data model in a read/write manner. When data binding is set up in this
fashion, the property reflects the value of the data and
changes to the property are propogated to the data model.
The BindingContext
Each Form has a BindingContext. The BindingContext is responsible for
managing the collections of data that controls are bound to. It manages currency
and dependency.
Currency: The BindingContext maintains a current position for
each collection. Simple data binding uses this current position to
determine which object in the collection to bind to a control property.
As the current position is changed, so does the object that a control
property is bound to. See Simple Data Binding.
Dependency: The BindingContext maintains dependency relationships
between collections. This allows for the creation of master/detail forms.
See Master Detail
Forms.