TIBLookupComboEditBox

TIBLookupComboEditBox is a TDBLookupComboBox descendent that implements "autocomplete" of typed in text and "autoinsert" of new entries.

Although TDBLookupComboBox also supports auto-complete, the benefit of using TIBLookupComboEditBox comes with long lookup lists as typing in one or more characters forces the list to be queried again and restricted to list members beginning with the same characters. The list of alternatives becomes much shorter.

Auto-insert normally uses the list dataset's insert query to add a new row and depends upon the dataset's “After Insert” event handler to set the other fields of the row to appropriate values and/or the generator assigned to the dataset.

TIBLookupComboEditBox Example

 
 

The above example can be found in ibx/examples/lookupcombobox and uses the Firebird “employee” example database. The “Employee Name” is a TIBLookupComboEditBox and is used here to:

  1. a)Select an employee record for editing 

  2. b)Initiate the entry of a new employee record. 

First, you should explore the use of the new control. Click on the drop down arrow and a drop down list of all employee names (in lastname/firstname syntax) will be shown. This is typically longer than can be displayed on a single screen.

 
 

Now close the drop down list, select all characters in the Employee Name edit box and enter “pa”. After a short (600ms) delay, after you stop typing, the employee details should change to that shown in Illustration 2 i.e. for the first employee with a lastname beginning with “pa”, i.e. Mary Page.

Of course, auto-complete to the first employee beginning “pa” may not get the actual employee you want. Now click on the drop down list and this will show all employees with a last name starting with “pa”. This is a much shorter list than the full list and allows you to quickly focus in on the employee you want.

Indeed, this can also be done from the keyboard. Start again, and enter “pa”, now press the down arrow and you can cycle quickly through all employees starting “pa”. The up arrow also works. Use the Enter key to select the employee record.

Alternatively, after entering “pa” and seeing the entry for Mary Page, then press “r” to extend the entry to “par” and you get the record for Bill Parker.

To return to the full list, just press the escape key while the control has the focus.

Auto-insert

Auto-insert allows quick insertion of new employee records. For example, start by selecting all text in the Employee Name edit box and enter the name of the new employee (e.g. Smith, John), and press the “Enter” key. You should now get a prompt confirming the entry of the new employee record:

 
 
The employee name is parsed from the text entered into the Employee Name box. The remaining fields come from defaults taken from the “OnInsert” event handler. You can now amend the defaults as required.
 

TIBLookupComboEditBox Properties

TIBLookupComboEditBox inherits TDBLookupComboBox properties. In addition, it defines:

AutoInsert

Boolean

Set to true to enable auto-insert

AutoComplete

Boolean

Default: true in TIBLookupComboEditBox

KeyPressInterval

Integer

Delay in milliseconds between last key press and auto-complete (Default: 500ms).

RelationName

String

TIBLookupComboEditBox updates the “Where” clause in the ListSource select SQL query in order to refine the list, and uses the value of the “ListField” property as the column name. If this name is ambiguous in the SQL query then the “RelationName” property must be set to the name of the table or table alias to qualify the column name and remove the ambiguity.

 

TIBLookupComboEditBox Event Handlers

OnAutoInsert

TIBLookupComboEditBox will normally use the ListSource's Insert query to perform auto-insert. If this is not possible or inappropriate then an OnAutoInsert handler must be provided to perform the insertion. The handler is provided with the value of the display text to insert and must return the new key value.

OnCanAutoInsert

This handler is called immediately before auto-insertion is performed and is typically used to validate the insert and obtain user agreement (e.g. via a dialog box).  The handler is provided with the value of the display text to insert and must set the “Accept” boolean on return to true to accept the insert or to false to reject it.