Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement find as you type on a TComboBox descendant [closed]

What is the correct way to implement the "find as you type" behavior on a TComboBox descendant component whose style is csOwnerDrawFixed?

like image 989
user16120 Avatar asked Oct 01 '08 22:10

user16120


1 Answers

  1. Use a TTimer (let's call it timIncSearch). Set (at design time) the following properties: Enabled:=False;
    Interval:=400; //empirically found - it's the delay used in Windows Explorer

...and in OnTimer you'll wrote your searching engine. Be sure that the first line here will be timIncSearch.Enabled:=False; Also because you use csOwnerDrawFixed perhaps it's better to enforce a repaint of your control.

As an aside, - just guessing because you didn't give us many details - perhaps you must hook OnEnter and OnExit events to custom open and close the DropDown list. (Normaly, this is achieved by setting the AutoDropDown property accordingly)

  1. In your ComboBox.KeyPress you'll write

with timIncSearch do
begin
Enabled:=False;
Enabled:=True;
end;

...also take care here, perhaps you must have a 'case Key of' construct to handle the #13 separately (or whatever).

Other hints:

  • depending on your situation, perhaps you must hook (also?) the OnKeyDown (if you want to process special keys like eg. BackSpace, Del, Arrows etc. - taking in account that the event repeats itself while the key it's pressed down) and/or OnKeyUp (if you want to do similar processing as above but without taking in account the keyboard's key auto-repeat feature).
like image 99
John Thomas Avatar answered Oct 10 '22 04:10

John Thomas