Skip to main content
A newer version of this page is available. .

Using a Lookup Column

  • 2 minutes to read

A lookup column allows you to display and edit records from a lookup dataset. This column type is handled by the LookupComboBox editor.

There are two ways to set up a lookup column.

The first is to connect your DBTreeListColumn to a lookup field that was created in Delphi’s persistent field editor. For more information on how to create a persistent Lookup field, see the ‘Defining a lookup field’ topic in the Delphi documentation. If a dataset contains a lookup field that is properly set up, a user just has to assign the lookup field name to the DBTreeListColumn.DataBinding.FieldName property.

The second way of setting up a lookup column is to use the column’s Properties or RepositoryItem property. The PropertiesClass property allows you to choose the column’s bound editor class. The RepositoryItem property allows you to choose one of the editors previously created. After an appropriate value to either of these properties, the Properties property will contain an object providing editor settings:

//...
TreeListUSERID.PropertiesClass := TcxLookupComboBoxProperties;
//...

If you choose the LookupCombo editor class, you will get an editor class that includes properties for configuring ListSource, ListColumns, and KeyFieldNames and the DataBinding.FieldName to replace the LookupComboBox.DataBinding property used to match the value of the lookup dataset field (KeyFieldNames).

Let’s examine how the TreeListUSERID lookup column is configured in the ExpressQuantumTreeList web demo, (the Task Manager module). The TreeListUSERID column is set up to show the full name of the person whose USERID field in the PROJECTS table matches the ID field in the USERS table. The following image shows the design time settings applied to the TreeListUSERID lookup column’s editor:

//...
TreeListUSERID.PropertiesClass := TcxLookupComboBoxProperties;
With TcxLookupComboBoxProperties(TreeListUSERID.Properties) do
begin
  ListSource := dsMain.dsUsers;
  ListFieldNames := 'FULLNAME';
  KeyFieldNames := 'ID';
end;
TreeListUSERID.DataBinding.FieldName := 'USERID';
//...

The following image shows the User column at runtime:

See Also