Data binding NET controls to your business objects

The .NET Compact Framework provides the BindingSource control, which allows you to set up data binding on the form. Drag a BindingSource control to the Accountviewer form. You can set up data binding using the following code. The first two lines of code pass the business object to the BindingSource control. The subsequent lines of code define the mapping between your business objects and your controls.

public void SetupBindings() {

AccountBindingSource.DataSource = typeof(BaseAccount); AccountBindingSource.Add(_account);

txtFirstName.DataBindings.Add(new Binding("Text", AccountBindingSource, "FirstName", true));

txtLastName.DataBindings.Add(new Binding("Text", AccountBindingSource, "LastName", true));

//Data binding a combobox txtLastName.DataBindings.Add(new Binding("SelectedIndex",

AccountBindingSource, "Status", true));

In the same fashion, establish the data bindings for the other controls on the

Accountviewer form.

Was this article helpful?

0 0

Post a comment