Modifying Drop-Down Menus on the fly

Tore Nilsen tore.nilsen at me.com
Wed Feb 10 15:27:04 EST 2016


What you are looking for is:

set the text of button “myMenu” to “myMenuList”

This can be called in a variety of handlers, at the latest in a mouseDown handler in the menu button itself.

Here is an example I used with my student the other day. They were supposed to make an application where the user should choose a starting point and an ending point for a journey, from a list of places along the route. This is a situation where you would like to filter out the starting point from the possible choices as ending point, and it is a good example of what you want to achieve. Here is a script in the menuPick handler in the first menu, that sets the options for the second menu:

on menuPick pItemName
   put the text of me into tText
   repeat with i = 1 to the number of lines of tText
      if pItemName = line i of tText then
         delete line i of tText
         exit repeat
      end if
   end repeat
   set text of button "No 2" to tText
   show button "No 2"
end menuPick


This script could also be put in a mouseDown handler in the button called “No 2” with som alterations:

on mouseDown 
   put the text of button “No 1" into tText
put the label of button “No 1” into tStart
   repeat with i = 1 to the number of lines of tText
      if tStart = line i of tText then
         delete line i of tText
         exit repeat
      end if
   end repeat
   set text of button "No 2" to tText
   show button "No 2"
end mouseDown

The number of "case entries" (menuLines) for an option menu, only apply to Windows and Linux, as they will show the option menu as a combo-box. The menuLines property defines how many lines will be displayed in the drop down list of a combo-box, without the need for scrolling. The total number of items in the menu can be any number, as the user can scroll further down the list in the combo-box.

Tore Nilsen





> 9. feb. 2016 kl. 20.44 skrev Francis Nugent Dixon <effendi at wanadoo.fr>:
> 
> Hi from Sunny Brittany (at least it was this morning !),
> 
> After many years of using buttons in my stacks, I am
> discovering the joys of using “Pull Down” menus (and
> about time too !).
> 
> I can change the script “cases” with the “set script” command,
> but I also want to know how to change the value of the menu options
> on the fly,  for example, if I have a menu option “Show Table”
> in my button, once I have shown the table, how can I modify
> the menu option to show “Hide Table”, assuming that I also
> set the case in the script to the new value, with new instructions.
> 
> I thought that it was possible to modify any button/field options
> on the fly, but I can’t grab the syntax of this requirement.
> 
> I also see that the number of case entries is defined in the button 
> specs. Can I change this also, or do I just set a maximum value
> 
> I know that Klaus has played with menus (seen on forums)
> Maybe he has an answer ?
> 
> -Francis
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list