Developing a User Interface > Custom Editing and Lookup > Lookup Value Lists |
In many cases, end users need to be able to select values from a list of options, a lookup list. Such list can be pre-defined or composed dynamically, for example, retrieved from a database. A lookup list consists of lookup items, each having two values: Value and ValueText. Value is the selected value of the constant. ValueText is its string representation displayed in the query. ValueText can be different from Value. For example, you may want to show customer names in a lookup list and in the query, but use a customer code in the generated SQL statement.
There are five ways to specify a lookup list for a field in C1QueryFrame:
Check the Use lookup values check box in the schema designer (in Folder Designer) and fill the grid with Value/ValueText pairs. The list specified in the schema will be shown in a combo box when the user edits the field in C1QueryFrame.
If you need to modify the lookup list at run time, check the Use lookup values check box in the schema designer and write code handling the LookupValues event, modifying the lookup list. It is also possible to leave the lookup list empty in the schema and specify it from scratch in the LookupValues event. In the LookupValues event procedure, assign arrays of the equal dimension to the Values and ValueCaptions arguments. The Values argument determines the values as they are stored in the user query and will be used for SQL generation, the ValueCaptions argument determines the strings that appear in the list for user selection. By default, lookup lists are shown in a combo box. Setting the EditorType argument in the LookupValues event, you can specify the desired presentation: selection combo, editable combo, or menu. If you need other presentation techniques, use Custom Editing or Modal Editing, see below.
Use the SetLookup method to retrieve a list of lookup values from the database. This method is a convenient shortcut for retrieving lookup lists. See an example in the SAMPLES directory. However, if your lookup list is a large table (thousands of records or more), this method may be not efficient enough, because it pre-fetches all the records every time you open the combo box. In such cases, you may consider using custom editing, see below.
Use Custom Editing implementing your custom editor as a combo box or another selection control filled with lookup data. An example of such code using standard DataCombo control can be found in the C1QueryUI user control in the USERCTL directory. If your lookup list is a large table (thousands of records or more), you must bear in mind that DataCombo may be not efficient enough, because it pre-fetches all the records. In such cases, you may consider using more optimized data-aware controls, such as TDBCombo, a part of ComponentOne True DBList product, see an example in the SAMPLES directory.
Use Modal Editing if you want to select values from a menu or in a modal dialog with list boxes or other selection controls.