TDBLookupCombobox
Can anyone help me to reproduce TDBLookupCombobox functionality in FireMonkey?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t know if there is a better solution but this is what i do:
Suppose you have Table1 with a Foreign Key to Table2.
Textproperty of the Combobox with thelooked up field in Table2 and fill the
Tagproperty with thePrimary Key of Table2.
lookup field and
Selected.Tagwith the Foreign Key in Table1.edit:
Check the SourceComponent property of your TBindList and TBindPosition.
TBindList should point to the BindScopeDB of Table2.
TBindPosition, instead, to the BindScopeDB of Table1.
ControlComponent should point to your TComboBox for both.
When you use TBindList,
Formatcollection expressions refer to the single item inside the ComboBox because it cycles for every row in your Table2 to fill the control. So ControlExpressions are the properties of each item:Text,TagNote: you don’t need
Selectedand these SourceExpressions:
FieldByName(LookedUpField).AsString,FieldByName(PK).AsIntegerPut these expressions in the
Formatcollection.TBindPosition, instead, refers always to the whole ComboBox so you need to use
Selected.ControlExpressions:
Selected.TagSelectedText(Self),SourceExpressions:
FieldByName(FK).AsInteger,FieldByName(LookupField).AsStringRemember that
PosSourcecollection is used to set “ControlExpressions TO SourceExpressions” assignments whilePosControlcontains “SourceExpressions TO ControlExpressions” assignments.Basically you need two things: change your selected item when Table1 cursor changes and set your FK using the Tag property of the selected item when user changes it.
So just put these in your PosControl collection:
SelectedText(Self)ControlExpressionFieldByName(LookupField).AsStringSourceExpressionand these in your PosSource collection:
Selected.TagControlExpressionFieldByName(FK).AsIntegerSourceExpressionIf you want to make a similar behavior of TDBLookupComboBox you have to put the Table in Edit state when the selected combobox item is changed.
When I tried Firemonkey some months ago I needed more expressions to update the same field shown in a StringGrid but I don’t know if there is a better solution for that. Hope someone else can answer and share his experience about this.
For more informations look for the examples included with XE2.
Hope this helped a bit.