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 realise automatic search feature in ComboBox 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
04-Oct-03
Category
VCL-General
Language
Delphi 3.x
Views
92
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Igor Siticov

How to realise automatic search feature in ComboBox?

Answer:

For including this functionality we shall just handle KeyPress event of ListBox or 
ComboBox. 
Below is demonstartion of this realisation: 

1. Add string variable to your form: 

1   type
2     TForm = class(TForm)
3       {....... }
4     private
5       FSearchStr: string;
6     end;


2. Add initialisation of this string variable in Form's OnCreate event: 

FSearchStr := '';

3. Type the following code in OnKeyPress event of ListBox or ComboBox: 
7   
8   procedure TForm1.ListBox1KeyPress(Sender: TObject; var Key: Char);
9   var
10    i: Integer;
11  begin
12    case Key of
13      #27:
14        begin
15          // Escape key, clear search string
16          FSearchStr := EmptyStr;
17        end; { Case Esc }
18      #8:
19        begin
20          // backspace, erase last key from search string
21          if Length(FSearchStr) > 0 then
22            Delete(FSearchStr, Length(FSearchStr), 1);
23        end; { Case backspace }
24    else
25      FSearchStr := FSearchStr + Key;
26    end; { Case }
27    if Length(FSearchStr) > 0 then
28      if Sender is TListbox then
29      begin
30        i := SendMessage(TListbox(Sender).handle, LB_FINDSTRING,
31          TListbox(Sender).ItemIndex, longint(@FSearchStr[1]));
32        if i <> LB_ERR then
33          TListbox(Sender).ItemIndex := i;
34      end
35      else if Sender is TCombobox then
36      begin
37        i := SendMessage(TCombobox(Sender).handle, CB_FINDSTRING,
38          TCombobox(Sender).ItemIndex, longint(@FSearchStr[1]));
39        if i <> LB_ERR then
40          TCombobox(Sender).ItemIndex := i;
41      end;
42    Key := #0;
43  end;


Now you'll see how it will work. 

			
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