cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
nikles
Level VI

Add Combo Box Choices

Hi.  Is there a way to add choices to a combo box after it has been created?

I've created combo box that lists several choices.  The final option in the list is to add more choices.  Afterwards, I'd like to update the choices given in the combo box to include the new choice.  I'd also like the user to be able to continue adding choices this way, if they choose.

I've looked into deleting the combo box and creating a new one using the updated list if the user selects the "add" choice, but that only works as many times as I can nest If clauses, and as I said, I'd like the user to be able to repeat this as many times as they like.  I tried using a recursive function to create a combo box, then if the "add" choice was selected, update the list of choices, delete the combo box, and recursively call the same function.  So far that's failed badly.  In general, combo boxes and functions do not seem to cooperate for me (I keep getting "name unresolved" errors).

Is there a simpler way to do what I'm trying to accomplish?  Perhaps not even using combo boxes?  Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: Add Combo Box Choices

This will do the trick.  Tried using Append Item but it didn't work with a variable.

New Window( "Example",

      cb = Combo Box(

            {"One", "Two", "Three"},

      ),

      tb = text edit box(),

      bb = button box("Append",

            new_text = tb << get text();

            cb_list = cb << get items();

            insert into(cb_list, new_text);

            cb << set items(cb_list);

      );

);

View solution in original post

9 REPLIES 9
mikedriscoll
Level VI

Re: Add Combo Box Choices

I've never used a combo box but it is probably similar to a col list box. Have you tried the append() function?  See if this gives you any ideas, it is a rough snippet of my code. If it isn't quite what you're after, post your code.

colListData = col list box(All, width(lbWidth)),

ButtonBox("Group By",colListG<<Append(colListData<<GetSelected)),

colListG = ColListBox(width(lbWidth),nLines(4)),

ButtonBox("Bin” colListB << Append(colListData<<GetSelected)),

colListB = ColListBox(width(lbWidth),nLines(1)),     

nikles
Level VI

Re: Add Combo Box Choices

Thanks but unfortunately, no this does not work.  "Append" can add display boxes (e.g. combo boxes) to the parent, but can not add/modify options to an existing display box.  In the example you provided, you're adding a collistbox to the parent.  What I want to do is more analagous to changing one of the arguments in the first collistbox and updating.

mikedriscoll
Level VI

Re: Add Combo Box Choices

I've been able to use the append function to add selected items.  The example above behaves the same way as many of JMP's platforms.  If you open up a data table and click the Distribution platform dialog, then you can selected one columns at a time and cast it into the Y role, one at a time. This is essentially how the append feature works in my code above. It checks to see what it selected in the column list box (at left in the distribution platform) and appends it to the Y list on the top right.

This was an example using columns. The first line wouldn't be relevant to you, that was more to show where the new selections were coming from for my code.  I don't want to tell you the wrong thing so I'll check the manual for combo boxes and get back to you later if I can make sense out of it. 

pmroz
Super User

Re: Add Combo Box Choices

This will do the trick.  Tried using Append Item but it didn't work with a variable.

New Window( "Example",

      cb = Combo Box(

            {"One", "Two", "Three"},

      ),

      tb = text edit box(),

      bb = button box("Append",

            new_text = tb << get text();

            cb_list = cb << get items();

            insert into(cb_list, new_text);

            cb << set items(cb_list);

      );

);

mikedriscoll
Level VI

Re: Add Combo Box Choices

Nice. Yeah i just tried using append and found it didn't work for combo box. Good to know.

djhanson
Level V

Re: Add Combo Box Choices

I'm running across an application in which being able to use Append() to modify the list within a ComboBox would be very helpful.  It can be done with a ListBox so I'm not sure why it cannot be done with a ComboBox?  The use case is that many times lists need to be updated dynamically and hence the Append() feature is quite useful with ListBox.

 

Anyways, if this is something a future JMP version could accomodate it would be helpful.  DJ

djhanson
Level V

Re: Add Combo Box Choices

Also meant to add, Remove All() also apparently does not work with the ComboBox (it does with the ListBox).  So that would be another nice feature for the ComboBox.  DJ

djhanson
Level V

Re: Add Combo Box Choices

Ok let me add as I experiment:

ListBox<<Append(mylist) ~ ComboBox<<Set Items(mylist).  So I guess there is a way to Append it's just not called Append :D  And I guess ListBox<<Remove All ~ ComboBox(mylist) where you just do mylist={};  My bad, it's just a bit confusing, that is different worded syntax for similar applications.  In my case I am resorting to a ComboBox now, as I can fake out a ListBox to only show nlines(2) within a tab, but as soon as I focus on another tab the Listbox bloats to 4 lines minimum (I wish we could just set the minimum of ListBox to nlines(1) really).  But at least with a ComboBox I can keep the vertical real estate (number of lines) to a minimum.  DJ

txnelson
Super User

Re: Add Combo Box Choices

I have read this discussion track multiple times to make sure the initial impression I got is valid.  That impression is that a lot of guessing as to what an object or function can do, and what the syntax might be if it may be able to do what is desired.

 

The current implementation of JSL is not consistant from object to object.  That is, how one works with a button box object, syntactically, and capability is not the same as one works with a list box object, etc.  However, all of the capabilities, and the syntax to use is detailed for each  funjction, object and display box is detailed in the Scripting Index.

 

Help==>Scripting Index

 

The question in this discussion track on if, and how a combo box can change is answered in the Scripting Index

scripting index combo box.PNG

If a capability isn't listed, the function/object/display box doesn't have that ability.  And if it does, the example will show you the syntax.

 

I recognized the confusion expressed in this discussion track, because it is where I used to live.  And the solution I found has been the Scripting Index.  I am too old to be able to keep all of the differences in the functions/objects/display boxes sorted out in my head.

Jim