VB.NET Developer's Guide

Data Binding

We have now discussed many ways of displaying information to the user and collecting information from the user. In most applications, the information displayed comes from a data source and the information collected goes to a data source. The Windows Forms framework allows you to bind data sources to forms, which is a very convenient way to open and save datasets. There are two types of data binding, and we discuss them in the following sections.

Simple Data Binding

In simple data binding, a single value within a data set is bound to a property of a component. For example, the Text property of a text box can be bound to the FirstName column of an Employees table. The following snippet shows the code for this scenario:

Dim dtEmployee As DataTableDim txtFirstName As New TextboxdtEmployee = dsDataSet.Tables("Employee")txtFirstName.Bindings.Add("Text", dtEmployee, "FirstName")

Because the binding is simple, only one first name will be shown at a time. This makes a text box a good choice for simple data binding text boxes contain only one piece of information at a time: the value of the Text property. Other controls such as combo boxes and list boxes expose an Items collection that can contain more than one piece of information at a time. These controls are good candidates for complex data binding, which we discuss in the next section.

Complex Data Binding

In complex data binding, a whole dataset is bound to a component. For example, a combo box...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Petroleum and Mineral Oil Products
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.