For the latest version of JMP Help, visit JMP.com/help.


Scripting Guide > Display Trees > Construct Custom Windows > Get and Set Selected Values of Display Elements That Return Lists
Publication date: 04/30/2021

Get and Set Selected Values of Display Elements That Return Lists

You can use the Set Selected(Item Number, <State>, <Run Script(0|1)>) message to pre-select an item. You can use this message separately to a saved display box reference, or you can specify it inline as a list box << message.

To retrieve the selected value, use the Get Selected message, which returns the value of the selected item. The Get Selected Indices message returns the index number of the selected item.

antennaList = {"Dish","Helical","Polarizing","Radiant Array"};
 
win = New Window( "Test List", // method 1: display box reference
	listObj = List Box(
		antennaList,
		Print(
			"iList",
			listObj << Get Selected,
			listObj << Get Selected Indices
		)
	)
);
listObj << Set Selected( 2, 1 );
 
win = New Window( "Test List", // method 2: inline
	listObj = List Box(
		antennaList,
		<<Set Selected( 2, 1 ),
		Print(
			"iList",
			listObj << Get Selected,
			listObj << Get Selected Indices
		)
	)
);

Both of these scripts print the following text to the log:

"iList"

{"Helical"}

{2}

In the preceding examples, the Print expression is executed when the Set Selected message is completed. To prevent the script from running, include Run Script(0) as the last argument. Run Script( 0|1 ) controls whether a display box on-change script runs after a Set or Set Selected message.

antennaList = {"Dish","Helical","Polarizing","Radiant Array"};
win = New Window( "Test List",
	listObj = List Box(
		antennaList,
		Print(
			"iList",
			listObj << Get Selected,
			listObj << Get Selected Indices
		)
	)
);
listObj << Set Selected( 2, 1, Run Script( 0 ) );

With Run Script( 1 ), the script is executed when the Set message is completed, even if the value is unchanged. (The script does not run again if the user selects the same value.) With Run Script( 0 ), the script does not run.

On most interactive display boxes, the script does not run on most interactive display boxes if you leave out Run Script(). However, on List Box(), the script runs by default, which is consistent with previous behavior.

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).