From Lazarus wiki
Revision as of 09:10, 2 February 2013 by BigChimp (talk | contribs) (added rxdblookupcombo)
Jump to navigationJump to search



Unit: Lazarus DbCtrls

Official documentation: TDBLookupComboBox


A (doubly) data-bound combobox. The TDBLookupCombobox control gets a list of values from its ListSource (which e.g. represents a table with product info, "Products"). It then

  • displays the values in the ListField (e.g. a "ProductName" field) while
  • remembering the values in the KeyField (e.g. an "ID" field)

The combobox stores the result (i.e. the KeyField value in the DataField, e.g. the "ProductID" field in the DataSource property (e.g. an "Orders" table).

The difference with the TDBComboBox is that the DBComboBox is a (as it were) "singly data bound control": it stores the results in a database fields but the list of values to select from is supplied by code/via the Object Inspector.

Unbound use

You can get the combobox to look up values from a table without storing the results by leaving the DataSource and the KeyField properties empty.


At least for DBLookupComboBox, there is a bug with FPC 2.6.0 (used in Lazarus 1.0, 1.0.2 etc) that requires the listfield to be present in the datasource as well.

Workaround: you can bypass this by declaring a calculated field with the same name as the listfield in the datasource's dataset that does nothing.

Alternative control

The Rx controls (in the RxNew package) have the RxDBLookupCombobox which has some extra functionality; it e.g. allows to display multiple fields/columns next to each other (much like MS Access comboboxes):

RxDBLookupCombo.LookupDisplay = 'field1;field2'; //takes a semicolon-delimited list of fields

It additionally has a property DisplayAllFields.