TOPIC: How do I populate dropdown list with column data?
#699
How do I populate dropdown list with column data? 3 Years, 6 Months ago
Hi, I am trying to populate a dropdown list with data from a table column. Here is what I have so far:

Create tables
Code:

create navyranks (rank) key(rank)

create servicemembers(rownum, rank, lastname, firstname)
key(rownum)


Create a library
Rule_rownum
Code:

function ()
    {
    return Timestamp();
    } 


My_NavyRanksAccess
Code:

#(Access navyranks
title: "Navy Ranks"
(rank group: 0)
)


My_ServiceMembersAccess
Code:

#(Access servicemembers
title: "Service Members"
(rownum group: 0) nl
(Control: (ChooseField ('navyranks.rank') group: 0) (firstname group: 1) (lastname group: 2)
)



What I would like is a dropdown list of Navy ranks (Ensign, Captain, Admiral...) from the rank column of the navyranks table.

In the My_ServiceMembersAccess, I attempted the use the ChooseFeild control, but cannot figure it out. I figure I need an index on the servicemembers table, but have no idea how to use it with a ChooseField control.

I know I could hardcode the field data, but I would rather give the end user the abilty to add/update/delete the dropdown list data.

I would be grateful for any assistance.
 
 
#700
Re:How do I populate dropdown list with column dat 3 Years, 6 Months ago
Hi, I think the IdControl is just what you need.

See in the User's Manual: "Going Further -> Using IdControl".
 
 
Mauro
 
#701
Re:How do I populate dropdown list with column dat 3 Years, 6 Months ago
IdControl is when the table has a timestamp key. KeyControl is probably what you want (since your ranks table does not have a timestamp key). They are very similar otherwise.

Another alternative if there will only be a small number of ranks is to use ChooseList with a rule supplying the list.

Code:

(ChooseList listField: ranklist)

Rule_ranklist
function ()
    {
    return QueryList('ranks', 'rank')
    }



Post edited by: andrew, at: 2007/02/14 00:26
 
 
andrew
 
#702
Re:How do I populate dropdown list with column dat 3 Years, 6 Months ago
Thanks for the assistance Mauro and Andrew. I was able to get the IdControl to work, but not the Key control. I decided to not use the ChooseList only because I would like provide an interface for the end user to enter or modify the data.

Once again, thanks for the help.
 
 
#703
Re:How do I populate dropdown list with column dat 3 Years, 6 Months ago
Glad you got it working.

The Accounting download is a good source of examples. The only problem is that it is large and complex so it can be hard to find what you want. But you can, for example, search for Key(Control) in the Field_ definitions.
 
 
andrew