So, I've been using LiveBindings between two tables at a combobox to get the Id and Description of a foreign key(with the Item.LookupData and Item.text properties) and assign the key to a field in another table with the SelectedValue propertie. This is working fine i guess but i'm using custom dbnavigator controls to make a "register form".
I'm using methods like this to make the inserts: adotablealuno.FieldValues['Nome']:=editnomeAluno.Text;
But I'cant find how to use the combobox in this way, i've already tried the ItemIndex and Selected properties, but none of this work (I'm using a Access DB btw). How can I use my foreign key in ComboBox for this?

- 99
- 8
1 Answers
Actually I was already stating this question and there was no good answer for a long time. I found a way out that I am currently using. At least I know that I'll get reliable data.
You need to handle OnFillingListItem
event of the LinkFillControlToField
link in alike way and store id number in ComboBox
Items. I use Tag
property for this purpose though it is not actually good.
procedure TForm1.LinkFillControlToField1FillingListItem(Sender: TObject;
const AEditor: IBindListEditorItem);
begin
(AEditor.CurrentObject as TListBoxItem).Tag :=
YourLookuptable.FieldByName('id').AsInteger;
end;
And then fetch the item id from ListBox1.Selected.Tag. The text value can be accessed via ComboBox1.Selected.Text
.
Appended.
You make an alike LinkFillControlToField
link.
Then you select this link and create an OnFillingListItem
event handler to the link (select events tab in the Object Inspector and double click on OnFillingListItem
ComboBox). The event handler (empty procedure) will appear. It will be given a name like TForm1.LinkFillControlToField1FillingListItem(...
Then you write the code setting the id property to the items' Tags.
-
I'll try this. I just don't get from which control this is. I put this in the combobox or the binding? – Guilherme Raguzzoni Nov 11 '15 at 18:23
-
@GuilhermeRaguzzoni I have appended my answer, however, I suppose that you have got it already. – asd-tm Nov 11 '15 at 18:42
-
Yes, I got that already, however, you made a great addition =) – Guilherme Raguzzoni Nov 12 '15 at 22:07