How to get SelectedValue ComboBox from code?

I am trying to create something like this TLookupComboBoxusing LiveBindings.

I posted the normal TComboBoxin VCL form. I also have a dataset with some rows that have two fields idand text.

Then I used the LiveBindings editor to create TBindSourceDBand TBindingsList.

There is only one binding in it:

object BindingsList1: TBindingsList
  Methods = <>
  OutputConverters = <>
  UseAppManager = True
  Left = 244
  Top = 229
  object LinkFillControlToField1: TLinkFillControlToField
    Category = 'Quick Bindings'
    Control = ComboBox1
    Track = True
    FillDataSource = BindSourceDB1
    FillValueFieldName = 'id'
    FillDisplayFieldName = 'text'
    AutoFill = True
    BufferCount = -1
    FillExpressions = <>
  end
end

As you can see, I have different fields for FillValueFieldNameand FillDisplayFieldName.

The constructor for LiveBindings is as follows:

BindSourceDB1 connected to ComboBox1

ComboBox is populated with values โ€‹โ€‹from the field text, so I think I configured it correctly.

How can I get SelectedValuefrom code?

TLabel, TLabel.Caption, , , ?

PS: , TDBLookupComboBox.

: TPrototypeBindSource, . TBindSourceDB TClientDataSet, , .

+4
2

TLinkFillControlToField:

procedure TForm1.ComboBox1Change(Sender: TObject);
var
    SelectedValue: Integer;
begin
    if TryStrToInt(LinkFillControlToField1.BindList.GetSelectedValue.AsString, SelectedValue) then
      DoSomethingWith(SelectedValue);
end;
+1

, . selectedIndex, . ComboBoxChange. :

selectedIndex := combobox1.ItemIndex;
0

Source: https://habr.com/ru/post/1540971/


All Articles