Topic: Add items to combobox

I cant find in the Manual how to add  items to Combobox?

Re: Add items to combobox

you can see attachment  as example from me
maybe can help you

Post's attachments

Attachment icon tes.rar 294.45 kb, 266 downloads since 2020-05-17 

3 (edited by derek 2020-05-18 16:23:36)

Re: Add items to combobox

Hi Markos,
There are different ways to add items to comboboxes.
For me, the easiest is to put all of the tables that you want to hold combobox values for on one form, access it using a 'showform' button and use editable grids to maintain them. 
It avoids having any script so there is no programming overhead when you need to add or change values.
More importantly, referential integrity is maintained which is not the case when you built combobox entries by script.
Having all your 'dictionary' maintenance on one form means it's also very easy to limit access to authorised users only.
Please see attached for an example.
Derek.

Post's attachments

Attachment icon markos.zip 337.84 kb, 302 downloads since 2020-05-17 

Re: Add items to combobox

Thanks.
I thought it was simpler, like in VB.net (add manually or by simple code).
What I need is to create two comboboxes with 3 items each (read only).
Is there something like radio button or list box instead?
Or I need to use the check boxes that is unsuitable for my applications because only one item must be selected.

Re: Add items to combobox

This works for me:

         procedure Form1_OnShow (Sender: TObject; Action: string);
begin
  Form1.ComboBox1.Items.Add('mm');
  Form1.ComboBox1.Items.Add('inches');

   Form1.ComboBox2.Items.Add('mm');
   Form1.ComboBox2.Items.Add('AWG');
   Form1.ComboBox2.Items.Add('SWG');
   
end;

One more thing.
Is there a possibility for the ComboBox to "remember" previously selected item  each time the program is opened?

Re: Add items to combobox

MarkoS,
If you do not want to use tables for storing combobox values as Derek provided, then you need to manually load the combobox through script. There are two options in how you store the combobox values. You can either store the actual text value from the combobox or you can store a numeric number (id) of the combobox value. Check out the two options in the attached example. FYI - Option 2 is the more efficient way for database applications. If you look at the raw data in the table you can see the difference between the two options in how the values are stored.

Post's attachments

Attachment icon Manual Load of Combobox.zip 336.97 kb, 320 downloads since 2020-05-18 

Re: Add items to combobox

ehwagner,
Thanks.
Works very nice.