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
81
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   
2   type
3     TForm = class(TForm)
4       {....... }
5     private
6       FSearchStr: string;
7     end;
8   
9   //2.Add initialisation of this string variable in Form's OnCreate event: 
10  
11  FSearchStr := '';
12  
13  //3.Type the following code in OnKeyPress event of ListBox or ComboBox: 
14  
15  procedure TForm1.ListBox1KeyPress(Sender: TObject; var Key: Char);
16  var
17    i: Integer;
18  begin
19    case Key of
20      #27:
21        begin
22          // Escape key, clear search string
23          FSearchStr := EmptyStr;
24        end; { Case Esc }
25      #8:
26        begin
27          // backspace, erase last key from search string
28          if Length(FSearchStr) > 0 then
29            Delete(FSearchStr, Length(FSearchStr), 1);
30        end; { Case backspace }
31    else
32      FSearchStr := FSearchStr + Key;
33    end; { Case }
34    if Length(FSearchStr) > 0 then
35      if Sender is TListbox then
36      begin
37        i := SendMessage(TListbox(Sender).handle, LB_FINDSTRING,
38          TListbox(Sender).ItemIndex, longint(@FSearchStr[1]));
39        if i <> LB_ERR then
40          TListbox(Sender).ItemIndex := i;
41      end
42      else if Sender is TCombobox then
43      begin
44        i := SendMessage(TCombobox(Sender).handle, CB_FINDSTRING,
45          TCombobox(Sender).ItemIndex, longint(@FSearchStr[1]));
46        if i <> LB_ERR then
47          TCombobox(Sender).ItemIndex := i;
48      end;
49    Key := #0;
50  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