Author: Tomas Rutkauskas
I wish to display a list. I can easily create the list by adding to Items.
Optionally the user can add an item to the list. When I tried it, the OnChange
event fired as soon as I pressed one key. I tried using the OnExit - this crashed
the app. How can the user type in a string and press Enter and get this added to
the list and selected?
By unassigning and re-assigning the OnChange event handler for the combobox.
1 procedure TForm1.Button1Click(Sender: TObject);
2 begin3 if Trim(Edit1.Text) <> EmptyStr then4 if ComboBox1.Items.IndexOf(Edit1.Text) = -1 then5 begin6 ComboBox1.OnChange := nil;
8 ComboBox1.ItemIndex := ComboBox1.Items.IndexOf(Edit1.Text);
9 ComboBox1.OnChange := ComboBox1Change;