Author: Tomas Rutkauskas
Is there a way to let a TComboBox do incremental search in its drop down list?
Currently it uses only the first letter so if multiple items start with the same
letter it's not very useful.
Answer:
Create a new Combo inherited from class(TcustomComboBox) and change the Change
Event to the following few lines:
1 {...}2 protected3 4 procedure Change; override;
5 {...}6 7 procedure TExtComboBox.Change;
8 var9 str: string;
10 Index: Integer;
11 begin12 inherited Change;
13 str := Text;
14 if (FLastKey = VK_DELETE) or (FLastKey = VK_BACK) then15 begin16 SelStart := Length(str);
17 SelLength := 0;
18 Exit;
19 end;
20 {try to find the closest matching item}21 Index := Perform(CB_FINDSTRING, -1, LPARAM(str));
22 if Index <> CB_ERR then23 begin24 ItemIndex := Index;
25 SelStart := Length(str);
26 SelLength := Length(Items[Index]) - SelStart;
27 end28 else29 Text := str;
30 {call standard event}31 if Assigned(FOnChange) then32 FOnChange(Self);
33 end;
34 end.