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 add items to a TComboBox upon an [ENTER] key press 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
68
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I would like my user to be able to enter items into a combobox and add each item 
upon pressing the enter key. Is there a simple way to do this. I started using 
csdropdown style. Then I tried using the keydown event with key 13, so that when 
the user presses enter, the user's entry is added to combobox.items, but so far its 
not working. I'll keep hacking away at it, but I thought perhaps there is an 
existing solution to this problem, either starting from a different control, or 
using a different method in TComboBox.

Answer:

This works for me on a csDropDown combobox (D5.01):
1   
2   procedure TForm1.ComboBox1KeyPress(Sender: TObject; var Key: Char);
3   begin
4     if key = #13 then
5     begin
6       if combobox1.text <> emptystr then
7         combobox1.items.add(combobox1.text);
8       key := #0;
9     end;
10  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