ComponentOne List 8.0 for ActiveX
A Simple Example

Consider the following form, which displays records from the Titles table of the familiar Biblio database supplied with Visual Basic.

Note that the PubID field of the Titles table corresponds to the PubID field of the Publishers table, which contains name and contact information. Therefore, you can enhance the interface of this form by using a TDBCombo control to provide a multicolumn drop-down list of publisher names.

At design time, delete the PubID text box and replace it with a TDBCombo control.To view items in the combobox, set the MaxComboItems property of the TDBCombo1 to 6. Note that the height of the text portion of the combo does not change.Add a new Data control (Data2) to the form and set its Visible property to False, since this control exists only to populate the combo box.

When you are finished, the form should look something like this:

Connect Data2 to the Publishers table by setting its DatabaseName (Data control) property to Biblio.mdb and its RecordSource (Data control) property to the following SQL query:

Select PubID, Name From Publishers

Set the RowSource property of TDBCombo1 to Data2.  At run time, this will populate the combo with the PubID and Name fields from the Publishers table. Set the BoundColumn property of TDBCombo1 to PubID.  Note that because you have already specified a RowSource, the drop-down list in the Visual Basic properties window shows all available fields (PubID and Name).

Next, set the DataSource property of TDBCombo1 to Data1 and the DataField property of TDBCombo1 to PubID. This specifies that the PubID field of the Titles table will be updated when the user selects an item from the combo box.

Finally, to provide more room for the list portion of the combo, set the DropdownWidth property of TDBCombo1 equal to the Width property of the Title text box.

Run the program and open the combo by clicking its drop-down button.The form will look something like this:

Note that the appropriate record in the Publishers table is automatically highlighted in the combo's drop-down list.  As you type characters, the highlighted item changes accordingly.For example, typing the numbers 1, 2, and 3 in succession positions the selected item to PubID 1, 12, and 123.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback