BuildComboList Method

Returns a ColComboList string from data in a recordset.

Syntax

[form!]VSFlexGrid.BuildComboList rs As Object, FieldList As String, [ KeyField As Variant ], [ BackColor As Variant ]

Remarks

The VSFlexGrid control has extensive support for drop-down lists and combo-lists when editing cells. This support includes multi-column drop-down lists, automatic value translation, and default field highlighting and relies on two properties, ComboList and ColComboList.

The syntax for creating the lists is simple, but creating the lists can be tedious. The BuildComboList method builds a ColComboList automatically from a recordset, reducing the amount of programming required.

The parameters for the BuildComboList method are described below:

rs As Object

An ADO or DAO recordset containing the values to be displayed on the grid.

FieldList As String

A string containing a comma-separated list of field names to be displayed. If the list contains more than one field, a multi-column drop-down list is created. You may define a default field (displayed in the cell when the list is closed) by preceding its name with an asterisk.

KeyField As String (optional)

The name of the field to be used as a key. This field must be numeric, and is usually the recordset's ID field.

BackColor As OLE_COLOR (optional)

The color used to paint the background of the default field while the list is displayed. If omitted, the whole list is painted using the current cells background color.

For example, the code below displays a list of products from the NorthWind database. The SupplierID and CategoryID columns use translated lists built with the BuildComboList method to convert the numeric IDs into company and category names. The code assumes you have created the following controls on the form:

 

Control Name

Description

fg

VSFlexGrid control, OLEDB version.

dataProducts

ADO Data Control bound to the NorthWind database, Products table.

dataSuppliers

ADO Data Control bound to the NorthWind database, Suppliers table.

dataCategories

ADO Data Control bound to the NorthWind database, Categories table.

 

   ' bind grid to Products table

    Private Sub Form_Load()

        fg.Editable = flexEDKbdMouse

        Set fg.DataSource = dataProducts

    End Sub

    Private Sub fg_AfterDataRefresh()

   

        ' map Suppliers column to display supplier info

        Dim s$

        dataSuppliers.Refresh

        s = fg.BuildComboList(dataSuppliers.Recordset, "*CompanyName,ContactName", "SupplierID", vbYellow)

        fg.ColComboList(fg.ColIndex("SupplierID")) = s

   

        ' map Category column to display category info

        dataCategories.Refresh

        s = fg.BuildComboList(dataCategories.Recordset, "*CategoryName,Description", "CategoryID", vbYellow)

        fg.ColComboList(fg.ColIndex("CategoryID")) = s

   

        ' make sure all columns are visible

        fg.AutoSize 1, fg.Cols - 1

    End Sub

See Also

VSFlexGrid Control