Select a pull down menu item from another handler...

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
tjo7777
Posts: 34
Joined: Fri May 02, 2014 9:16 pm

Select a pull down menu item from another handler...

Post by tjo7777 » Wed Feb 25, 2015 5:41 am

I have a pull down menu with several options available.

Is there a way I can change the selection of the pull down menu from another handler?

I tried a bunch of things like this:

Code: Select all

if item = 6 then
     
     set the selection of button "Custom Items" to menuitem 6
 
       end if
I tried all the variations I could think of without success.

Thanks to anyone who can offer suggestions or advice,

TJ.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Select a pull down menu item from another handler...

Post by Klaus » Wed Feb 25, 2015 1:50 pm

Hi TJ,

sorry, I don't have the slightest idea what you are after,
and your (invalid) script snippet is also not very enlightening.

Do you mean:
When the user selects any menuitem of menu btn "menuA" then you want also to
execute the command of the coresponding (same line in menu?) menuitem of btn "menub"
as if the user selected that menuitem with the mouse?


Best

Klaus

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Select a pull down menu item from another handler...

Post by magice » Wed Feb 25, 2015 3:07 pm

If you just want to change the displayed choice of the dropdown, you can do it by changing the "label". If you want to simulate the choice of one of the items, then try this:

Code: Select all

send "menuPick myChoice" to btn "myDropDownBtn" 

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Select a pull down menu item from another handler...

Post by Klaus » Wed Feb 25, 2015 3:13 pm

magice wrote:If you just want to change the displayed choice of the dropdown, you can do it by changing the "label".
Yep, that was what I also thought first, but the TS is talking about PULL-DOWN menu buttons, which do not have a (dynamic) label like e.g. an option-button.

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Select a pull down menu item from another handler...

Post by magice » Wed Feb 25, 2015 3:26 pm

Klaus wrote: Yep, that was what I also thought first, but the TS is talking about PULL-DOWN menu buttons, which do not have a (dynamic) label like e.g. an option-button.
Yes, I see what you mean. So, he must want to simulate the choice.

tjo7777
Posts: 34
Joined: Fri May 02, 2014 9:16 pm

Re: Select a pull down menu item from another handler...

Post by tjo7777 » Wed Feb 25, 2015 3:55 pm

Thank you for all the replies, sorry if I did a poor job of explaining my issue.

I was looking for something like what magice posted.

Code: Select all

send "menuPick myChoice" to btn "myDropDownBtn"
Basically I want to simulate a choice being made on the drop down menu.

As Klaus pointed out it does not seem to have a dynamic label, so its not as easy as setting the label to a new value.

Thanks for all the help. I don't know if its possible to do this, but I do appreciate all your efforts and replies.

TJ

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Select a pull down menu item from another handler...

Post by magice » Wed Feb 25, 2015 4:02 pm

tjo7777 wrote:Thank you for all the replies, sorry if I did a poor job of explaining my issue.

I was looking for something like what magice posted.

Code: Select all

send "menuPick myChoice" to btn "myDropDownBtn"
Basically I want to simulate a choice being made on the drop down menu.

As Klaus pointed out it does not seem to have a dynamic label, so its not as easy as setting the label to a new value.

Thanks for all the help. I don't know if its possible to do this, but I do appreciate all your efforts and replies.

TJ
sending menuPick should work, but you will need to use the actual choice as written in in the button ("myChoice" in the above example) instead of a menuItem number.

tjo7777
Posts: 34
Joined: Fri May 02, 2014 9:16 pm

Re: Select a pull down menu item from another handler...

Post by tjo7777 » Wed Feb 25, 2015 4:32 pm

Hi magice,

Thank you for your help.

I did try using menuPick and it did not seem to work on the drop down type menu.

However to my pleasant surprise today it seems to work using "set the label of btn". I swear yesterday I tried that and it didn't work?! Probably it was my mistake.

Anyway I came up with a sort of work around for using this drop down menu.

Code: Select all

 set the label of button "Custom Tags" to "Custom Tag 6"
       put the label of button "Custom Tags" into currenttag
   put currenttag into line 5 of field "Field"
In this way I can set the value of the label, and then use that label value as a way to know what the current selection is.

You need to be careful though, because you can set the value of the label to anything, even things that are not listed as choices in the dropdown menu. So in a way the menu is just a kind of window dressing when I use it this way. Its probably not the way the designers intended the dropdown menu to be used, but it seems to work for my application.

Thanks again for your help,

TJ.

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Select a pull down menu item from another handler...

Post by Klaus » Wed Feb 25, 2015 4:40 pm

Hi TJ,

yes, mis-using a pulldown menu button to change its label IS in fact a violation of any thinkable HIG :D

But ou can also "trigger" a menu item if you only have the NUMBER of that item:
...
set the menuhistory of btn "your pull-down here" to 2
...
Will cause the same as if the user had selected that secdond menu item!


Best

Klaus

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: Select a pull down menu item from another handler...

Post by magice » Wed Feb 25, 2015 4:58 pm

Klaus wrote:Hi TJ,

yes, mis-using a pulldown menu button to change its label IS in fact a violation of any thinkable HIG :D

But ou can also "trigger" a menu item if you only have the NUMBER of that item:
...
set the menuhistory of btn "your pull-down here" to 2
...
Will cause the same as if the user had selected that secdond menu item!


Best

Klaus
menuHistory! that is what I was trying to remember. I have spent the last 45 minutes going through the dictionary in an attempt to find it. Do what Klaus said, use menuHistory.

tjo7777
Posts: 34
Joined: Fri May 02, 2014 9:16 pm

Re: Select a pull down menu item from another handler...

Post by tjo7777 » Wed Feb 25, 2015 7:59 pm

THANK YOU!!! :D
Yes, it seems menuhistory is what I was looking for! I did try to search on my own for quite a while, but somehow missed this.

Cheers,

TJ.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9580
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Select a pull down menu item from another handler...

Post by dunbarx » Wed Feb 25, 2015 10:20 pm

Gee, I read this entirely differently. And wrongly, perhaps.

I thought, because of:

Code: Select all

Is there a way I can change the selection of the pull down menu from another handler?
I thought the OP wanted to be able to open an ad hoc set of choices from a pulldown from a running handler:

Code: Select all

put yourNewList into button "yourPullDown"
click at the loc of btn "yourPullDown"
Thus reloading the menu options as needed, and open that menu for selection. Totally wrong, I suppose?

Craig Newman

mrcoollion
Posts: 719
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Select a pull down menu item from another handler...

Post by mrcoollion » Tue Jul 24, 2018 7:24 pm

Small addendum to this older post.

This is also possible:

Code: Select all

if the label of button "MyPulldownmenuButtonName" = line 1 of button "MyPulldownmenuButtonName" then set the label of button "MyPulldownmenuButtonName" to line 2 of button "MyPulldownmenuButtonName"

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”