1
votes

I have a TSQLDataset, Im using the livebindings to bind it to a listbox. When I click on the listbox item, I want to be able to access the other fields of data from the record, but I cannot figure out how to do it because I cannot get the dataset to the corresponding item.
I know that I could possibly take the ID Field and maybe assign it to Selected.Tag using live bindings but can't figure that out either, but if I could then I could have another a SQLQuery and then just return the result of the query

SELECT * FROM Dataset WHERE ID=(Tag value)

That would work, but I don't know how to get livebindings to set the items tag value when live bindings populates the Listbox.

Does anyone know how to make this work?

2
Did you ever figure this out because I'm now having the same issue?J__

2 Answers

1
votes

It is easier to link Tag property of the ListBox with the ID of the record.

-1
votes

There's a Sensor Info demo application from Embarcadero in XE5 Samples directory...

There you have OnItemClick = lbMainItemClick in TListBox events then you have to define the event handler:

procedure TfrmAboutSensors.lbMainItemClick(const Sender: TCustomListBox; const Item: TListBoxItem);
begin
  if Assigned(Item.OnClick) then
    Item.OnClick(Item);
end;

And then for every item on the list:

for LItem in LListBox do
begin
    //LItem.ItemData.Accessory := TListBoxItemData.TAccessory.aDetail;  // my code
    //LItem.ItemData.Accessory := TListBoxItemData.TAccessory.aNone;    // my code
    LItem.OnClick := ListBoxItemClick;
end;

Please give us callback if that helps.