Binding Data to Individual Controls on a Form

Another kind of data binding that you will commonly want to do is to bind properties on data items in a collection of data to properties on individual controls on a form. As mentioned earlier, this form of data binding is called simple data binding. To perform simple data binding, you use the DataBindings collection that every control inherits from theControl base class implementation of IBindableComponent. The DataBindings property exposes a collection of Binding objects, each of which represents an individual association between a data member within a data source and a property on the control itself.

A straightforward example of using simple data binding is to bind individual columns within a table to the Text property of TextBox or Label controls on a form, so the presented text in those controls shows the values from the current row of data in the table. If we extend the example shown in Figure 3.1 and add a set of text boxes to the form below the grid using the designer, we can add data binding so those text boxes will show the contents of some of the columns of the current row in the Customers table (see Listing 3.4).

0 0

Post a comment