Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to create a TComboBox with incremental search capabilities Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
27-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
66
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			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   protected
3   
4   procedure Change; override;
5   {...}
6   
7     procedure TExtComboBox.Change;
8     var
9       str: string;
10      Index: Integer;
11    begin
12      inherited Change;
13      str := Text;
14      if (FLastKey = VK_DELETE) or (FLastKey = VK_BACK) then
15      begin
16        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 then
23      begin
24        ItemIndex := Index;
25        SelStart := Length(str);
26        SelLength := Length(Items[Index]) - SelStart;
27      end
28      else
29        Text := str;
30      {call standard event}
31      if Assigned(FOnChange) then
32        FOnChange(Self);
33    end;
34  end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC