Browse DevX
Sign up for e-mail newsletters from DevX


A Look Under the Hood of Windows Forms Data Binding : Page 4

In Windows Forms, the data binding machinery is highly sophisticated and designed to meet common needs of former client/server applications, now migrating to the more modern .NET multi-tier design. The binding manager is a logical component that plays a key role as it enables data-bound controls grouped in a container control and bound to the same data source object to detect each other's changes and reflect their own user interface automatically.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

The PropertyManager Class
The PropertyManager class maintains a binding between a data source object's property and a data-bound control property. It differs from CurrencyManager in that it doesn't manage a list of values but it does manage single property values.

Table 2 lists the methods defined on the base binding manager class and overridden by derived classes.

Table 2: Methods supported by binding managers.

Method Name



Adds a new item to the underlying list. It has no effect on a PropertyManager object.


Cancels the current edit. The method is supported only if the data source implements the IEditableObject interface. In .NET Framework 1.x, the only class that implements this interface is DataRowView.


Ends the ongoing edit and saves changes.


Get or sets the list of property descriptors for the data source.


Removes an item at the specified position in the underlying list. It has no effect on a PropertyManager object.


Resumes a previously suspended data binding process.


Suspends a data binding process on a data source.

The SuspendBinding and ResumeBinding methods allow the temporary suspension and resumption of data binding on a given data source. This typically happens when you want to allow the user to make several edits to data fields before validation occurs. In a complex user interface, it is common that you need to change one field in accordance with a second, but changing the first field may cause temporary inconsistency in the second field until you change that too. Because the data binding process is automatic in nature you would get an exception. To avoid that exception, suspend binding and resume it when all values are consistent again.

The PropertyManager gets into the game when you use simple bindings such as when you link a control's property to a data source column—for example, you may want the Text property of a Label to display the LastName column of the Employees table.

Binding b1; b1 = new Binding("Text", m_dataSet, "Employees.LastName"); lblLastName.DataBindings.Add(b1)

The code above creates a Binding object between a property named Text and the LastName column in the Employees table within the specified DataSet. The Binding object doesn't know anything about controls. It merely represents a logical property-to-column relationship. The binding becomes effective only when you add the Binding object to the DataBindings collection of a live control.

When you add a Binding object to the DataBindings collection of a Windows Forms control, a property binding manager is set up to guarantee that a property with the specified name is given the value of the specified column for the current record. I'll return later to the topic of Binding objects when I show you how to implement data binding with pictures and special data types.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date