How to get Item.LookupData and SelectedValue (as integer) of an FMX TComboBox at runtime?

asd-tm picture asd-tm · Jul 16, 2015 · Viewed 7.9k times · Source

There is a ComboBox on the FMX Form. It is binded with a datasource (table that has an id-integer and speciality - varchar fields) in the following manner-

object LinkFillControlToField1: TLinkFillControlToField
      Category = 'Quick Bindings'
      Control = ComboBox1
      Track = True
      FillDataSource = BindSourceDB1
      FillValueFieldName = 'id'
      FillDisplayFieldName = 'speciality'
      AutoFill = True
      BufferCount = -1
      AutoBufferCount = False
      FillExpressions = <>
      FillHeaderExpressions = <>
      FillBreakGroups = <>
    end

It is simple to get access to the value of chosen speciality (from ComboBox1.Selected.Text) but I can not find a way to access the id value of the selected item without extra SQL requests. Where is it stored in TComboBox or its ListBox? Where is SelectedValue stored and how to get it (as integer)?

Answer

Pau Dominguez picture Pau Dominguez · Jul 22, 2015

tm. You must set the livebinding link between the SelectedValue of the combo with an other control. I have attached a screeshoot of the binding editor. The label will show the id. enter image description here