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 begin4 if key = #13 then5 begin6 if combobox1.text <> emptystr then7 combobox1.items.add(combobox1.text);
8 key := #0;
9 end;
10 end;