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
miguello
Level VI

Need help with populating Col List Box

Part of my App's GUI has a button that opens a table, and a Col List Box that I need to populate with columns from that table.

If I open the table first and then create Col Lis Box as in this modified Example from Scripting Index, everything works fine:

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
New Window( "Col List Box Example",
lb = Col List Box()
);

lb << Append (dt << Get Column Names);

However, if I create the window with GUI that has button to open the table, i.e. I create Col List Box first and then open the table, it stops working. This is a simplified version of real code but it has the same problem - Col List Box does not populate with column names. 

Names Default To Here( 1 );
open = Expr(dt = Open( "$SAMPLE_DATA/Big Class.jmp" ); lb << Append (dt << Get Column Names););
gui = Expr(V List Box(btn = Button Box ("OPEN", open), lb = Col List Box()));

New Window( "Col List Box Example",
	gui;
);

What am I doing wrong? How can I make it work?

3 REPLIES 3
miguello
Level VI

Re: Need help with populating Col List Box

Ok, it looks like when ColListBox is created it is connected to the current data table. And you can only add columns from that DT.

So, since I need to show columns from different DTs in my GUI in the same COlLIstBox, I need to redefine it each time. Delete the old one and create a new one instead.

This seems to be working, please let me know if there is a better solution:

Names Default To Here( 1 );
open = Expr(dt = Open( "$SAMPLE_DATA/Big Class.jmp" ); refreshColList;);
refreshColList = Expr(
	(pb << Child) << Delete Box;
	pb << Append(lb = Col List Box(dt, all));
);
gui = Expr(V List Box(btn = Button Box ("OPEN", open), pb = Panel Box("Column List", lb = Col List Box())));

New Window( "Col List Box Example",
	gui;
);
miguello
Level VI

Re: Need help with populating Col List Box

Since I use this Col List Box to cast columns in many different roles using buttons and another Col List Boxes (as in any platform), I need to re-create MANY col list boxes, with different settings etc. So I wrote an universal function for that:

refreshDisplayBox = Function({dt, box, expr},
	parent = box << Parent;
	box << Delete Box;
	parent << Append(box = expr);
	Return (box);
);

dt is needed here in case if it is used in expr to re-create the Display Box. It gets passed into the function regardless of what handle for that table you're using outside of the function. Just need to remember to write all the expressions with "dt" for that.

Then the script is going to look like this:

 

Names Default To Here( 1 );

refreshDisplayBox = Function({dt, box, expr},
	parent = box << Parent;
	box << Delete Box;
	parent << Append(box = expr);
	Return (box);
);
colListExpr = Expr(Col List Box(dt/*use generic dt*/, all));

open = Expr(dtEXT/*different table name*/ = Open( "$SAMPLE_DATA/Big Class.jmp" ); lb = refreshDisplayBox(dtEXT/*pass it into the function*/, lb, colListExpr));

gui = Expr(V List Box(btn = Button Box ("OPEN", open), pb = Panel Box("Column List", lb = Col List Box())));

New Window( "Col List Box Example",
	gui;
);

Let me know if this is a valid approach.

 

ih
Super User (Alumni) ih
Super User (Alumni)

Re: Need help with populating Col List Box

Yes this is a valid way to approach this. I re-wrote this slightly to show another way to get to the same result:

 

Names Default To Here( 1 );

LoadTable = function( {dtname}, {dt, lbnew},
	dt = open("$SAMPLE_DATA/" || dtname);
	lbnew = Col List Box(dt, all);
	window:lb << Delete Box;
	window:pb << Append( window:lb = lbnew );
	win << Bring Window to Front;
);

win = New Window( "Col List Box Example",
	vlb = V List Box(
		H List Box(
			window:clb = List Box( { "Big Class.jmp", "Iris.jmp" } ),
			window:btn = Button Box ("OPEN", LoadTable((window:clb << Get Selected)[1]) )
		),
		window:pb = Panel Box("Column List", 
			window:lb = Col List Box()
		)
	)
);