A typical HTML menu has a label and a corresponding value. I'm new to LiveCode but all the examples I've seen here of populating a menu from a database show only the label being populated. Will the control accept both a label and a value such as:
AK 1
AL 2
AR 3
Where the label is a state name but the value returned is an id. The ID would be the primary key on the database table.
Populating menu with label and value
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Populating menu with label and value
Hi electricclay,
welcome to the Forum.
using a popUp menu on a Mac you can do this
New stack, 1 field, 1 popUp menu button
set the script of the popUp menu to
what is visible is "AK,AL,AR", the message on menupick sends "1,2,3" respectively.
This should work for Windows too. Can not test. Might even work with other types of Menu-Buttons in Windows.
see "Menu" in the dictionary though the entry is a bit opaque. Just ask here.
Menus are a bit tricky in Livecode because of different Human Interface Guidelines between the Operating systems.
Kind regards
Bernd
welcome to the Forum.
using a popUp menu on a Mac you can do this
New stack, 1 field, 1 popUp menu button
set the script of the popUp menu to
Code: Select all
on mouseDown
put "AK /|1" & cr & "AL/|2" & cr & "AR/|3" into tTemp
set the text of me to tTemp
end mouseDown
on menuPick pItemName
put pItemName into field 1
end menuPick
This should work for Windows too. Can not test. Might even work with other types of Menu-Buttons in Windows.
see "Menu" in the dictionary though the entry is a bit opaque. Just ask here.
Menus are a bit tricky in Livecode because of different Human Interface Guidelines between the Operating systems.
Kind regards
Bernd
Re: Populating menu with label and value
What Bernd said.
But this concept is easy. All buttons have a text property, but only menu style buttons will display that data directly. The menuItems of a menu style button in LC are simply the contents of the button. So in any button of any kind, you can:
The label of a menu style button is the currently selected menuItem. So to get at that "Y", you could
Same thing, but each has it strengths. Invoking either action sets the property of the other.
In an ordinary button, you would:
Just takes a little practice.
Craig Newman
But this concept is easy. All buttons have a text property, but only menu style buttons will display that data directly. The menuItems of a menu style button in LC are simply the contents of the button. So in any button of any kind, you can:
Code: Select all
put "X" & return & "Y" & return & "Z" into button "yourButton"
Code: Select all
set the label of btn "yourButton" to "Y"
or
Set the menuHistory of btn "yourButton" to 2
In an ordinary button, you would:
Code: Select all
answer line 2 of btn "yourButton"
or even:
set the label of btn "yourButton" to line 2 of btn "yourButton"
Craig Newman
-
- Posts: 2
- Joined: Wed Feb 17, 2016 10:38 pm
Re: Populating menu with label and value
Thanks I'll play around with both solutions.