Generate a Matrix of Selectable checkboxesAll,
Wondering what is the easiest way to generate a matrix of selectable checkboxes . So what i would like to be able to do is - generate a non- square matrix and pop it up for the user to select any position in the matrix the user would like. As long as the user can select multiple rows within a column and vice versa - it would be good to meet the need. Any help is appreciated.
Re: Generate a Matrix of Selectable checkboxesI realize I'm late to the game, and hopefully you've already figured this out. The main issue is you never displayed the Table Box in your code. I believe the next issue is you analyze the table right after creating it. I imagine you want to do this after the user has a chance to check the boxes. Hopefully the below code is closer to what you are looking for.
Names Default To Here( 1 );
InputsLoadBasic = Expr(
LB1 = Lineup Box( N Col( 2 ) );
LB1 << Append(
Panel Box( "Test",
V List Box( V List Box( Text Box( "Arg1" ), NEB_arg1 = Number Edit Box( 2 ), Text Box( "Arg2" ), NEB_arg2 = Number Edit Box( 3 ), ) )
)
);
LB1 << Append(
Panel Box( "Selectable Matrix Test",
V List Box(
Button Box( "Enter Target Matrix",
nR = 12;
nC = 24;
SCB1 = String Col Box( "", {} );
if(!isempty(TB1),
TB1 << Delete Box;
);
For( i = 1, i <= nR, i++,
SCB1 << Add Element( Char( i ) )
);
TB1 = Table Box( SCB1 );
For( i = 1, i <= nC, i++,
Insert Into( TB1, Check Box( Repeat( {" "}, nR ), <<SET heading=""></SET>Re: Generate a Matrix of Selectable checkboxes@Justin_Chilton / @txnelson / @thomasz
I have a follow up question, wondering if any of you could think of a way to do this. I am trying to generate the matrix of selectable boxes within a Panel Box. Here is the script, I have, wondering if you could guide as to why I am failing ?
InputsLoadBasic =
Expr(
LB1 = Lineup Box( N Col( 2 ) );
LB1 << Append(Panel Box( "Test",
V List Box(
V List Box(
Text Box( "Arg1" ),
NEB_arg1 = Number Edit Box( 2 ),
Text Box( "Arg2" ),
NEB_arg2 = Number Edit Box( 3 ),
)
)
)
);
LB1 << Append(Panel Box( "Selectable Matrix Test",
V List Box(
Button Box("Enter Target Matrix",
nR = 12;
nC = 24;
SCB1 = String Col Box( "", {} );
For( i = 1, i <= nR, i++,
SCB1 << Add Element( Char( i ) )
);
TB1 = Table Box( SCB1 );
For( i = 1, i <= nC, i++,
Insert Into( TB1, Check Box( Repeat( {" "}, nR ), <<SET heading=""></SET>
The resulting UI looks like what I want, however, when I click on the "Enter Target Matrix" button shown above, it does not do what I want. Can you please help
Re: Generate a Matrix of Selectable checkboxesYou can add a heading to a CheckBox within a TableBox using the <
nRow = 5;
nCol = 6;
// string col box for row labels
scb = String Col Box( "", {} );
// add labels to rows
For( i = 1, i <= nRow, i++,
scb << Add Element( "row" || Char( i ) )
);
// create a table box to contain everything
tbl = Table Box( scb );
// add all columns with the given number of rows
For( i = 1, i <= nCol, i++,
Insert Into(
tbl,
Check Box(
Repeat( {" "}, nRow ),
<<SET heading=""></SET>
Window:

Re: Generate a Matrix of Selectable checkboxes@Justin_Chilton,
1 follow up question I have is - Is it possible to add text on top of each column and at the beginning of each row ?
If so, what would be an efficient way to do it ? Should each of them be wrapped in a text box ?
Re: Generate a Matrix of Selectable checkboxes@uday_guntupalli,
You can use a CheckBox() within a Table Box to create a table of check boxes.
nRow = 5;
nCol = 6;
// create a table box to contain everything
tbl = Table Box();
// add all columns with the given number of rows
For( i = 1, i <= nCol, i++,
Insert Into( tbl, Check Box( Repeat( {" "}, nRow ) ) )
);
New Window( "Check Box Example",
tbl,
Button Box( "Show results",
// initialize the result
result = {};
// loop through each row
For( i = 1, i <= nRow, i++,
// initialize the row list
result[i] = {};
// loop through each column getting values
For( j = 1, j <= nCol, j++,
result[i][j] = tbl[CheckBoxBox( j )] << get( i )
);
);
// convert the list to a 2-d matrix
result = Matrix( result );
Show( result );
)
);
Here's what the window looks like:

And here's the result in the log with the above selected Check Boxes:
result =
[ 1 0 0 0 0 0,
0 1 0 0 0 0,
0 0 1 0 0 0,
0 0 0 1 0 0,
0 0 0 0 1 0];
Re: Generate a Matrix of Selectable checkboxes@thomasz,
I think for my needs - it looks good. However, if I may - I have a couple of follow up questions:
1. Are the selected positions retrievable ? - If yes- can you kindly provide an example of how to retrieve that data ?
2. Is it possible to add a little more text around this window ? More like an X - axis label and a Y-Axis label
Re: Generate a Matrix of Selectable checkboxesNot a very elegant solution, but something like this may work:
lv={};
for(i=1,i<=4,i++, insert into(lv,""));
tCB="";
for(j=1,j<6,j++,tCB||="check box( (lv)),");
tCB=substr(tcB,1,length(tCB)-1);
eval(parse(eval insert("wind=new window( \!"Check boxes\!",
H List Box(
^tCB^))")));