1 (edited by jumper 2015-12-15 16:37:49)

Topic: Add items to a combo box

First of all, I hope you will forgive my ignorance where Pascal is concerned. I promise I'll get better smile
 
I'm trying to find out how to add text to a combo box. I want to fill it up with the two character state abbreviations. I've been looking for an example all morning and haven't found one that works yet. Would someone please help an old guy out?

Nothing inspires forgiveness quite like revenge.

Scott Adams

Re: Add items to a combo box

procedure getItemToCB(var cb:TComboBox;text:String );
var
    i:integer;
begin
    i:=1;
    while(i<cb.items.count)do
    begin

        cb.ItemIndex :=i;
        if(cb.Text=text)then
        begin
            i:=cb.items.count+5;
        end
        else
        begin

           cb.ItemIndex :=0;
        end;
        i:=i+1;
    end;

Then use :

getItemTOCB(Form1.Combobox1,'NAME LASTNAME');

Re: Add items to a combo box

Thanks a bunch krokodil_sk. I haven't tried it yet, but I will in just a little bit.

Nothing inspires forgiveness quite like revenge.

Scott Adams

Re: Add items to a combo box

Hi Jumper,
Apologies if I've misunderstood your question.
You can't (easily) populate entries directly into a combo-box (like in Excel).  Entries need to be added to a table first like any other data field(s). 
Once created, these entries are then referenced by using a combo-box on the form where the data is required. 
I've attached a knock-up (it's easier to show it than to explain).  I've used 3 different 'styles' for the combo-box entries with 3 discrete 'save' buttons:
1. the 2 digit state code
2. the state description
3. the two concatenated together
Obviously, you wouldn't normally have all 3 on the same form, I've just done it to show you the options you have.
Hope this helps,
Derek

Post's attachments

Attachment icon jumper combobox.zip 336.27 kb, 677 downloads since 2015-12-15 

5 (edited by jumper 2015-12-15 19:54:39)

Re: Add items to a combo box

Hi Derek. Thanks for the project. I just tried to see how everything was put together. However, I have to admit that I don't understand how the combo boxes are populated?? Form3 was the one that I was most interested in because of the three ways the combo boxes showed data.
   
I looked at the script file and only saw a "hello world" example. I have to leave in a few minutes, but will check this thread when I get back.
 
Thanks for the help
 
Edit: Also you should know that I'm clueless when it comes to database and database design...

Nothing inspires forgiveness quite like revenge.

Scott Adams

Re: Add items to a combo box

Good Evening Jumper,
It's 'standard' MVD which is why the script is empty (apart from the "hello world").

Using the example I knocked up, the 2 digit code and the description are fields in a table called 'states';  it is the table that gets populated, NOT the combobox.  The combobox is just a way of letting you pick a value from the 'states' table.  It is not a table itself and doesn't hold any data.
Have a look at the attached screenshot and follow it through.
On Form1 click the 'STATES TABLE' button.  This takes you to Form4 which is a list of rows in the 'states' table that have been added so far. 
Click  the 'ADD STATE' button to create more entries in the 'states' table..
When you have finished, go back to Form1 and click on the 'ADD' button to go to Form3 where you start adding suppliers. 
This is where you see the combobox in action - remember, it is simply a convenient way of presenting you with a pick-list of values held in the 'states' table.
Hope this clears things up a bit and if you need any more help, just shout.
Derek.

Post's attachments

Attachment icon jumper01.jpg 135.25 kb, 313 downloads since 2015-12-16 

Re: Add items to a combo box

Thanks for the extra information. I "get it" now smile This will certainly solve my problems. Also, I don't need a combo box either.
   
Thanks a bunch!

Nothing inspires forgiveness quite like revenge.

Scott Adams