XE3 Visual LiveBindings: Link a list control to a field

Posted by on in Blogs
List controls can be linked to data source fields. TListBox, TComboBox and VCL TListView are examples of list controls. When a list control is linked to a data source field, the selected item in the list control corresponds to the value of the data source field. To change the value of the field, the user selects a different item in the list control.

Typically, two data sources are used with a list control. One data source provides the value to select in the list control. The other data source provides the values to fill the list control. LiveBindings uses the terms "DataSource" and "FillDataSource".

The TPrototypeBindSource is a simple way to create data sources. We can configure one TPrototypeBindSource as the "DataSource" and another as the "FillDataSource".

First, create the "DataSource".

  1. New VCL application

  2. Drop a TPrototypeBindSource on the form

  3. In the object inspector, set PrototypeBindSource1.RecordCount to 10

  4. Add a ColorsName field to the TPrototypeBindSource (See this post for instructions on adding fields)

Next, create the "FillDataSource"

  1. Drop a second TPrototypeBindSource on the form

  2. In the object inspector, rename to "PrototypeBindSourceFill"

  3. Add a ColorsName field to the PrototypeBindSourceFill

  4. Name the field "AColorsName"

  5. Uncheck "Shuffle" and "Repeat" to generate an ordered list of unique values

Drop a TListBox on the form.

Choose the "View/LiveBindings designer" command to show the LiveBindings designer:

In the LiveBindings designer, ListBox1 is shown with three members: "SelectedValue", "Item.Text", and "Item.LookupData".

Connect "PrototypeBindSource1.ColorsName1" to "ListBox1.SelectedValue". Connect "PrototypeBindSourceFill.AColorsName" to "ListBox1.Item.Text".

ListBox1 is populated in the form designer.

"Darkgreen" is selected because the value of the "ColorsName1" field in the first record of PrototypeBindSource1 is "Darkgreen".

Right click on PrototypeBindSource1 and choose "Add Navigator". Now the app is ready to run.

The selection in the list box will change as the user changes the active record using the navigator.
I've added a TLabeledEdit to show how selecting a value in the listbox changes the value of the field.

Here is the complete design:

My next post will describe how to use the "Item.LookupData" member to create a lookup list.


  • Guest
    Evariz Sunday, 14 October 2012

    Another nice post about XE3 LiveBindings!

    Jim do you mind if i translate your LiveBindings series to french and publish them in my website? of course credit and links will go back to you.

  • Guest
    Jim Tierney Monday, 15 October 2012

    Hi Evariz, You may translate the series to French and publish on your website.

  • Please login first in order for you to submit comments
  • Page :
  • 1

Check out more tips and tricks in this development video: