Is there way to reflect hierarchy of columns when creating the list / combo box ?
region ==> Asia
country ==> china
select region first and then select country in the sub-category in the listbox
Here is an example that might help you:
dt = Open("$SAMPLE_DATA/Cars 1993.jmp");
Summarize(lstMake = By("Manufacturer"));
Insert Into(lstMake,"Select...",1);
nw = New Window( "Select Car Type",
Border Box(Top(10),Left(20),Right(20),
Lineup Box(NCol(1),
cb = ComboBox(lstMake, <<Script( doSelection() ) ),
lb = List Box( {}, Width(100), NLines(6) ),
Border Box( Left(120), Top(4), Bottom(4), Right(4),
Button Box( "OK", doOk() )
)
);
doSelection = Function({},
make = cb<<Get Selected;
rows = dt << Get Rows Where( AsColumn("Manufacturer")== make );
lstModel = Column("Model")[rows];
lb << Remove All;
lb << Append( lstModel );
dt << Clear Select;
doOk = Function( {},
cbSel = cb << Get Selected;
lbSel = lb << Get Selected;
nw << Close Window;
Show( cbSel, lbSel );
Here's a function 'hierListBox()':
//******************************************************************************************
// ian.cox@jmp.com: 04Sep2007
//
// Makes a "hierarchical" ListBox, where the contents displayed for the second list is
// conditional on the current selection in the first list. Multiple selections in both lists
// are allowed.
Clear Globals();
hierListBox = Function( {dt, c1, c2, winTitle},
// Make the requisite mapping: m maps each unique value in c1 to all corresponding
// values in c2
m = [=> ];
For Each Row(
k = c1[Row()];
If( !(m << Contains( k )),
m[k] = {}
m[k] = Insert( m[k], c2[Row()] );
// Build initial UI
l1 = c1 << GetValues;
l2 = c2 << GetValues;
lb1 = List Box( l1, lb1Script( lb1 ) );
lb2 = List Box( l2 );
nw = New Window( winTitle,
lb1,
lb2,
H List Box( Button Box( "OK", OKScript ), Button Box( "Cancel", nw << CloseWindow ) )
// Script that executes when the selection in lb1 is made or changed (updates contents of lb2)
lb1Script = Expr(
slb1 = lb1 << GetSelected;
l2new = {};
For( i = 1, i <= N Items( slb1 ), i++,
Insert Into( l2new, m[slb1[i]] )
lb2 << Delete;
lb2 = List Box( l2new );
nw[ListBoxBox( 1 )] << SibAppend( lb2 );
// When the user selection is made . . .
OKScript = Expr(
nw << CloseWindow;
l1 = lb1 << GetSelected;
l2 = lb2 << GetSelected;
// Make a list of the selections from the two list boxes
l = Eval List( {l1, l2} );
// Table . . .
dt = New Table( "Test",
Add Rows( 20 ),
New Column( "State",
Character,
Nominal,
Set Values(
{"FL", "FL", "NC", "MI", "AZ", "MI", "NC", "MI", "AZ", "FL", "FL", "NC", "FL", "NC", "MI", "FL", "FL",
"MI", "NC", "NC"}
),
New Column( "City",
{"City 1", "City 2", "City 3", "City 4", "City 5", "City 6", "City 7", "City 8", "City 9", "City 10",
"City 11", "City 12", "City 13", "City 14", "City 15", "City 16", "City 17", "City 18", "City 19",
"City 20"}
// Columns . . .
c1 = Column( dt, "State" );
c2 = Column( dt, "City" );
// Make map . . .
l = hierListBox( dt, Column( "State" ), Column( "City" ), "Conditional" );
Show( l );