cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
DSA
DSA
Level III

Listbox on selection event?

Hey,

i am trying to build a very small UI component in JSL after not doing this for quite a number of years and i find my self struggling.

 

I have a list of tables in a listbox, and i want to display a description of the table when it is selected in the listbox,
Here is a minimal example:

DSA_0-1707483306390.png

tables = {"Table1", "Table2"};
descriptions = {"This is the first table", "This is the second"};

showDescription = Function({},{sel, selIdx, desc},
    sel = item_disp_box << Get Selected;
    If(Nitems(sel) > 0,
        selIdx = loc(tables,sel[1])[1];
        desc = descriptions[selIdx];
        tb << Set Text(desc);
    );
);


nw = new window("Browse Tables",
	spacer box(size(0, 5)),
	hlistbox(
		panelbox("Tables:",
			spacer box(size(0, 5)),
			item_disp_box = listbox(tables, width(200), nlines(5), max selected(1)),
			//item_disp_box << On Something??(showDescription),
		),
		panelbox("Description of selected table:",
			tb = Text Box(""),
		),
	);
);

You can see that i've experimented with a function that will display the correct description in the code above and that works fine if i run it manually.

 

My problem is that i can't find a good trigger for that function for the listbox. I've been trough the scripting index and i can only find "on close".

Is there an easy way to achieve what I am looking for here?

 

Thanks in advance,

Daniel

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
mmarchandTSI
Level V

Re: Listbox on selection event?

Here's the <<Set Function (list box) example from the Scripting Index.

 

Names Default To Here( 1 );
New Window( "Example",
	lb = List Box( {"First Item", "Second Item", "Third Item", "Fourth Item"}, width( 200 ), max selected( 2 ), nlines( 5 ) ),
	Text Box( "" )
);
lb << Set Function( Function( {thisBox}, (thisBox << sib) << Set Text( Char( thisBox << get selected ) ) ) );

View solution in original post

jthi
Super User

Re: Listbox on selection event?

You have three options: On Change, << Set Function and << Set Script. You can find examples for all of these from scripting index (the examples might not include List Box, but they should work for it in similar manner as the other display boxes used to demonstrate). I would most likely use << Set Function as it provides reference to "itself" (listbox calling the function).

-Jarmo

View solution in original post

3 REPLIES 3
mmarchandTSI
Level V

Re: Listbox on selection event?

Here's the <<Set Function (list box) example from the Scripting Index.

 

Names Default To Here( 1 );
New Window( "Example",
	lb = List Box( {"First Item", "Second Item", "Third Item", "Fourth Item"}, width( 200 ), max selected( 2 ), nlines( 5 ) ),
	Text Box( "" )
);
lb << Set Function( Function( {thisBox}, (thisBox << sib) << Set Text( Char( thisBox << get selected ) ) ) );
jthi
Super User

Re: Listbox on selection event?

You have three options: On Change, << Set Function and << Set Script. You can find examples for all of these from scripting index (the examples might not include List Box, but they should work for it in similar manner as the other display boxes used to demonstrate). I would most likely use << Set Function as it provides reference to "itself" (listbox calling the function).

-Jarmo
DSA
DSA
Level III

Re: Listbox on selection event?

Thank you both! The Set Function worked like a charm