cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Ksrzg01
Level I

Update a List Box Based on a Combo Box Selection

Hello all,

 

So I have a few lists, in this case fruit and vegetables, and based on my selection on the combo box I would like to populate the list box with the new list. For example, if I have "fruit" selected, I want the list box to display oranges, apples, and grapes. The script I have works, but it doesnt evaluate the list AND I also do not want it to keep appending the list box with my selection. Is there a way around this?

 

 

TestArray = {"Fruit", "Vegetables"}; //my list of 'stuff'
Fruit = {"Oranges", "Apples", "Grapes"};
Vegetables = {"Corn", "Squash", "Eggplants"};


nw = New Window( "Sample",
	<<Modal,
	vlb = H List Box(
		cb = Combo Box(
			TestArray,
			tb2 << Append(cb << Get Selected);
		),
		tb2 = List Box()
	)
);

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Update a List Box Based on a Combo Box Selection

The main issue is that what is returned from the 

cb << Get Selected

is not a variable name, as you were wanting it to be, but rather a string, "Fruit" or "Vegetables".  That is, the names of the 2 list are Fruit and Vegetables, not "Fruit" and "Vegetables".

Below is a script that works the way you want.  There are other ways to do this, that others may want to contribute

Names Default To Here( 1 );
TestArray = {"Fruit", "Vegetables"}; //my list of 'stuff'
Fruit = {"Oranges", "Apples", "Grapes"};
Vegetables = {"Corn", "Squash", "Eggplants"};


nw = New Window( "Sample",
	<<modal,
	vlb = H List Box(
		cb = Combo Box(
			TestArray,
			tb2 << remove all;
			If( (cb << Get Selected) == "Fruit",
				tb2 << Append( Fruit ),
				tb2 << Append( Vegetables )
			);
		),
		tb2 = List Box()
	)
);

 

Jim

View solution in original post

4 REPLIES 4
uday_guntupalli
Level VIII

Re: Update a List Box Based on a Combo Box Selection

@Ksrzg01,

Try this. The list needs to be evaluated before its elements can be populated into the list box and a way to acheive it is as shown below.

TestArray = {"Fruit", "Vegetables"}; //my list of 'stuff'
Fruit = {"Oranges", "Apples", "Grapes"};
Vegetables = {"Corn", "Squash", "Eggplants"};
MyLists = {Fruit,Vegetables}; 

nw = New Window( "Sample",
	<<Modal,
	vlb = H List Box(
		cb = Combo Box(TestArray,
						MySelection = cb << Get Selected; 
						tb2 << Append(Eval(Parse(Eval Insert("\[^MySelection^]\"))));
					  ),
		tb2 = List Box()
	)
);

 

Best
Uday
txnelson
Super User

Re: Update a List Box Based on a Combo Box Selection

The main issue is that what is returned from the 

cb << Get Selected

is not a variable name, as you were wanting it to be, but rather a string, "Fruit" or "Vegetables".  That is, the names of the 2 list are Fruit and Vegetables, not "Fruit" and "Vegetables".

Below is a script that works the way you want.  There are other ways to do this, that others may want to contribute

Names Default To Here( 1 );
TestArray = {"Fruit", "Vegetables"}; //my list of 'stuff'
Fruit = {"Oranges", "Apples", "Grapes"};
Vegetables = {"Corn", "Squash", "Eggplants"};


nw = New Window( "Sample",
	<<modal,
	vlb = H List Box(
		cb = Combo Box(
			TestArray,
			tb2 << remove all;
			If( (cb << Get Selected) == "Fruit",
				tb2 << Append( Fruit ),
				tb2 << Append( Vegetables )
			);
		),
		tb2 = List Box()
	)
);

 

Jim
Ksrzg01
Level I

Re: Update a List Box Based on a Combo Box Selection

Thanks Nelson! One last question, when I do tb2 << Get Selection, I get an output in {"Apples"} format, any way to convert to just "Apples"? Substr and Word function are not working.

txnelson
Super User

Re: Update a List Box Based on a Combo Box Selection

1. What has been returned is a List.  To get the specific value from a list, all you have to do is to ask for the specific element from the list.  In your case, there is only one element being returned, so you just have to specify

(tb2 << Get Selection)[1]

2. Your venture into JSL will remain a mistery until you spend the time reading the Scripting Guide.  It describes not just the syntax, but even more impotantly, the language structures( Lists, Matrices, etc. ).

     Help==>Books==>Scripting Guide

Jim