Advanced Data-Bound Controls VB Help

In this section, we are going to look at three data-bound controls that are quite different from those we’ve used so far:

  1. The data-bound List control
  2. The data-bound ComboBox control
  3. The data-bound Grid control

. .
Unlike the other data-bound controls, these controls can display fields from multiple rows. The data-bound List control is similar to the regular ListBox control and can be populated with an entire column of a RecordSet. The data-bound List control has all the functionality of the regular ListBox control, and in addition, allows the use’lo enter new values (records). The data-bound Grid control is similar to the Grid control and can display an entire RecordSet. Each row of the grid holds a row (record) of the RecordSet, and the RecordSet’s columns correspond to the columns (fields) of the RecordSet,

These two data-bound controls aren’t installed by default. To use them in your projects, you must first add them to the Toolbox. To do so, follow these steps:

  1. Right-click the Toolbox and select Components to open the Components dialog .box .
  2. Check the Microsoft Data Bound Grid Control and the Microsoft Data Bound List Control boxes.
  3. Click the Close button to close the Components dialog box.

Using the Data-Bound List Control

The data-bound List control can be bound to a specific column of the RecordSet and is commonly used as a lookup table. Figure 17.21 shows how the data-bound List control can be used as a lookup table to simplify navigation in a RecordSet.

The data-bound List control is different from the data-bound controls we have looked at thus far: it can connect to two data controls. It has the standard Data- Source/DataField properties, which are used just like any other data-bound control, and it has RowSource/ListField properties that determine how the control is populated:

  1. RowSource specifies the source (RecordSet or Data control) for populating the list.
  2. ListField specifies the field that will be used to fill the list.

VB6 at Work: The DBList Project

The DBList application demonstrates the use of the data-bound List control as a navigation tool. The Form you see in Figure 17.21 contains a number of fields from the Products table in the NWIND database. Design the Form shown in Figure 17.21 by binding the various textboxes to their corresponding fields through a Data control.. as if you were going to navigate through the list of products with the buttons on·the Data control.

The problem with the Data control is that you can’t really use it to navigate through RecordSet, even if it’s indexed, because you only see one record at a time. If you could place the key values in a ListBox control and use it as a navigation tool, you would have a much more convenient user interface.

Place a data-bound List control on the Form, and set its RowSource property to the name of the Datal Data control and its ListField property to the name of the field you want to display in the list. For the DBList application, this is the Product- Name field. The DataSource and DataField properties of the data-bound List control
are empty.

If you run the application now, nothing will happen, because you haven’t specified how the List control should react to the Click event. Basically, you want to reposition the Data control to the row of the RecordSet that has the  matching Product Name field. To do this, insert the following code in the List control’s Click event:

The Bookmark property identifies a row in the RecordSet. By setting this property to a value, you are in effect forcing the Data control to be repositioned to the specified row. The control’s SelectedItem property is not .the text displayed in the edit box of the control, but the bookmark of the record to which the selected field belongs. This code repositions the Data control in the RccordSet and updates the
data-bound labels on the Form. For a single line, the DBList application sure does a lot.

Posted on November 6, 2015 in Database Programming with Visual Basic

Share the Story

Back to Top