Export (0) Print
Expand All

Visual Basic Concepts

Visual Studio 6.0

Using the DataCombo and DataList Controls

The DataCombo and DataList controls strongly resemble the standard list box and combo box controls, but there are some important differences that give them great flexibility and usefulness in database applications. Both controls can be automatically filled from a database field from the data control to which they are bound. In addition, they can optionally pass a selected field to a second data control, making them ideal for "lookup table" applications.

Possible Uses

  • In a relational database, use the data from one table to supply values to be input into a second (related) table. For example, in an inventory database, the names of suppliers are stored in one table with each supplier having a unique ID. Another table showing products uses the unique ID to designate which company supplies the product. Use the DataList control to show the name of the supplier while (invisibly) supplying the ID of the supplier to the products table.

  • Allow the user to narrow a search by selecting a criteria from a drop-down list. For example, a sales-reporting database application might use a DataList control to let the user pick a State or Sales Region. Once that selection is made, the choice is automatically passed to a second data control that positions itself on sales records from the selected region.

Like their built-in counterparts, the main difference between the DataList and the DataCombo controls is that the DataCombo box control provides a text box into whose contents may be edited.

For More Information   For an explanation of the DataList and DataCombo controls' ability to link database tables, see "Linking Two Tables using the DataCombo and DataList Controls." To build a simple application using linked tables, see "Creating a Simple DataCombo Application."

Noteworthy Properties of the Controls

Some important properties of the DataList and DataCombo controls include:

Property Description
BoundText Contains the value of the field named in the BoundColumn property.
SelectedItem Returns a bookmark for the row of a selected item.
MatchEntry Enables extended search mode for locating items in a list generated by the DataCombo control.
IntegralHeight Sizes the control to display an exact number of complete rows.
VisibleCount Specifies the number of visible items in a list.

Note   The DataFormat property of the DataCombo control is an Extender property. Therefore it's always visible on the property sheet and can be set in code. However the DataCombo control only formats the top item in its list. This can be disconcerting to the end user who sees a formatted top item, but is only given a list of unformatted items to select from. The formatted item may also mislead end users who assume the item will be entered in the database as formatted. For these reasons, it's advisable to not set the DataFormat property when using the DataCombo control.

For More Information   To try a step-by-step tutorial that demonstrates the use of the BoundText property, see "Creating a DataGrid Linked to a DataList Control." For a complete list of properties and methods of these controls, see "DataList Control" and "DataCombo Control."

Show:
© 2015 Microsoft