beau36
asked on
Add Incremental Search to ComboBox Items
How can I perform an incremental search in a regular combobox that would work like Delphi's Help/Index functionality?
The best I could do is..
procedure TForm1.cb1KeyPress(Sender: TObject; var Key: Char);
var
X : integer;
begin
if CB1.DroppedDown = false then CB1.DroppedDown := true;
if ((Key > #31) and (Key < #127)) or (Key = #13) then
begin
if Key <> #13 then
CB1.ItemIndex := -1;
for X := 0 to CB1.Items.Count - 1 do
if Pos(CB1.Text, CB1.Items[X]) = 1 then Exit;
end;
end;
The best I could do is..
procedure TForm1.cb1KeyPress(Sender:
var
X : integer;
begin
if CB1.DroppedDown = false then CB1.DroppedDown := true;
if ((Key > #31) and (Key < #127)) or (Key = #13) then
begin
if Key <> #13 then
CB1.ItemIndex := -1;
for X := 0 to CB1.Items.Count - 1 do
if Pos(CB1.Text, CB1.Items[X]) = 1 then Exit;
end;
end;
I thought there was a standardized way to do this... ..I forgot how.
http://www.borland.com/delphi/news/zd/1998/jul98/
This example uses a list box and edit box to perform an incremental search.
This example uses a list box and edit box to perform an incremental search.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try the OnChange event.
Put there some code that runs through your list and finds and selects it (combobox1.itemIndex := x;)
you shouldn't use pos, it also find substrings. You could write a loop in the loop that compares the CB1.text with the CB1.Items[x]; caracter by caracter, with something like:
//mainloop for.....
begin
....
inputInList := true;
//caracterloop for.....
begin
...
if combobox1.text[y] =combobox1.items[x][y] then
inputInList := false;
end;
///if inputInlist is true here, than input is equal to first caracters of item in list, so make it the focused one.
end;
Greetings,
Floris.