TDBLookupComboBox

From Lazarus wiki
Revision as of 16:15, 16 December 2012 by BigChimp (talk | contribs) (added bug info)
Jump to navigationJump to search

Template:Translate

Definition

Unit: Lazarus DbCtrls

Official documentation: TDBLookupComboBox

Description

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.

Bugs

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.