Difference between revisions of "TDBLookupComboBox"

From Free Pascal wiki
Jump to navigationJump to search
(added bug info)
(added rxdblookupcombo)
Line 21: Line 21:
  
 
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.  
 
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):
 +
<syntaxhighlight>
 +
RxDBLookupCombo.LookupDisplay = 'field1;field2'; //takes a semicolon-delimited list of fields
 +
</syntaxhighlight>
 +
It additionally has a property DisplayAllFields.
  
 
[[category:Lazarus]]
 
[[category:Lazarus]]
 
[[category:dbctrls]]
 
[[category:dbctrls]]
 
[[Category:Databases]]
 
[[Category:Databases]]

Revision as of 09:10, 2 February 2013

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.

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.