Re: adding items to a combo boxPosted by Jean Claude Servaye on May 11, 2001 at 19:05:41: In Reply to: adding items to a combo box posted by p12114-andrew on May 10, 2001 at 02:12:07: Place a combobox on your form and add the following code:
procedure TForm2.ComboBox1KeyPress(Sender: TObject; var Key: Char);
var
N : Integer;
begin
If Key = #13 then begin // user press enter in the combobox
N := Combobox1.Items.IndexOf(Combobox1.Text); // search if the Item already exist
If N = -1 then Combobox1.Items.Add(Combobox1.Text); // if not, add it
end;
Combobox1.Items.SaveToFile('Combo.Txt'); // and save the list in a file
end;
procedure TForm2.FormShow(Sender: TObject);
begin
// when your form is displayed, get the items from the file
If FileExists('Combo.Txt') then
ComboBox1.Items.LoadFromFile('Combo.Txt');
end;
|
|