0

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?

1 Answers1

2

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. enter image description here

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.

Community
  • 1
  • 1
asd-tm
  • 3,381
  • 2
  • 24
  • 41