I am trying out the TAdvSearchEdit and I'm constantly refilling it with a backgroudquery on entering text. So my searchlist is not static.
I have filled the Object values of the Searchlist.Items with the IDs of the connected itgems from the database. But now I have to find out on Enter which item has been selected.
In your sourcode I see an ItemIndex, but that value is reset before I can use it.
Where can I get this value? Preferably in an Event of course.
As there was no answer yet to this question, I have put a lot of effort in it to get some result, but I'm beginning to think that what I want is not possible, what would be a shame.
What I do is this:
- I fill the Searchlist with a query to the database in the OnChange event:
procedure TForm1.ZoekParentChange(Sender: TObject);
var
hv : TList<Thv>;
nAantal: Integer;
nTeller: Integer;
S : TSearchListItem;
const
nMax : Integer = 8;
begin
hv := FindItems('naam', ZoekParent.Text, '', 0, nMax + 1);
if hv <> nil then
begin
ZoekParent.SearchList.BeginUpdate;
Try
ZoekParent.SearchList.Items.Clear;
nAantal := hv.Count;
if nAantal > nMax then nAantal := nMax;
for nTeller := 0 to nAantal - 1 do
begin
ZoekParent.SearchList.Items.Add(hv[nTeller].naam.ValueOrDefault);
ZoekParent.SearchList.Items[ZoekParent.SearchList.Items.Count - 1].&Object := TObject(hv[nTeller].bedrijvenid);
end;
if nAantal < hv.Count then ZoekParent.SearchList.Items.Add('+ + + +');
Finally
ZoekParent.SearchList.EndUpdate;
hv.Free;
End;
end;
end;
This fills the searchbox on the fly with new, better results as I type.
When I see the result I want, I click on it with the mouse, or go to it by keyboard and press Enter.
That gives me an Editbox with the desired result as Text. But I don't know which ID in the background was selected.
The result seems to disappear before I can use it.
I hope you can offer me a soution, because the searchmechanism works great like this.
The TAdvSearchEdit was not designed with this usage in mind. The TAdvSearchEdit will do the filtering for matching items itself and does not expect its item list to be changed behind its back.
Can you perhapt suggest another component to achieve this with?
I don't want to use a data aware component, because these don't work well with the Aurelius or XData query. I tried that, but it does not work well.
Sorry, I cannot think of a direct equivalent.
We are not aware of issues with DB-aware components and Aurelius or XData datasets.
If some issue might persist with this, please report this in the Aurelius & XData forums.
I didn't mean to suggest the data-aware components are not working with e.g. the TAureliusDataset. I just don't want to use it that way.
You can get the index of the selected item in the dropdown list via:
I cannot see that the list would be empty when OnDropUp is happening.
From your descriptions, we did already a lot of time consuming guesswork and trial & error.
We will investigate and report by email.