Choose Language Hide Translation Bar
Highlighted
uday_guntupalli
Level VIII

Generate a Matrix of Selectable checkboxes

All, 
   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. 

 

 

Best
Uday
2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
thomasz
Level IV

Re: Generate a Matrix of Selectable checkboxes

Not 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^))")));

View solution in original post

Highlighted

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:

Capture.PNG

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];

 

 

Justin

View solution in original post

7 REPLIES 7
Highlighted
thomasz
Level IV

Re: Generate a Matrix of Selectable checkboxes

Not 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^))")));

View solution in original post

Highlighted
uday_guntupalli
Level VIII

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 

Best
Uday
Highlighted

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:

Capture.PNG

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];

 

 

Justin

View solution in original post

Highlighted
uday_guntupalli
Level VIII

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 ? 

 

 

Best
Uday
Highlighted

Re: Generate a Matrix of Selectable checkboxes

You can add a heading to a CheckBox within a TableBox using the <<Set Heading message. You can also add row labels by placing a StringColBox as the first column in the Table Box.

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( "col" || Char( i ) )
		)
	)
);

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 );
	)
);

Window:

Capture.PNG

Justin
Highlighted
uday_guntupalli
Level VIII

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( Char( i ) ) ) )
															   );
															   
															// initialize the result
															ResMat = {}; 
															// loop through each row
															For( i = 1, i <= nR, i++, 
																	ResMat[i] = {};
																	// loop through each column getting values
																	For( r = 1, r <= nC, r++,
																			ResMat[i][r] = TB1[CheckBoxBox( r )] << get( i )
																	   );	
															   );
															// convert the list to a 2-d matrix
															ResMat = Matrix( ResMat );
													
														  )
										      )
							   )
					 );
	); 
InputsLoadBasic;

InputsUnloadBasic =
Expr(
		V List Box(
					Align( center ),
					LB1,
					H List Box(
								Button Box( "OK", 
																																															
											// Unload PV Prediction Details 
											arg1 = NEB_arg1 << Get; 
											arg2 = NEB_arg2 << Get; 
																	
											ResultMatrix = Matrix( ResMat );
																																			
										  )// end of button box 
							 )// end of H List Box 
				  )// end of V List Box
	); 
	
NW1 = New Window("TestUI",
					V List Box(
								InputsLoadBasic;
								InputsUnloadBasic;
							  )
				);

image.png

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 

Best
Uday
Highlighted
msharp
Super User

Re: Generate a Matrix of Selectable checkboxes

I 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( Char( i ) ) ) )
					);
					
					LB1 << Append(TB1);
				)
			)
		)
	);
);
InputsLoadBasic;

InputsUnloadBasic = Expr(
	V List Box(Align( center ),
		LB1,
		H List Box(
			Button Box( "OK", 
				// Unload PV Prediction Details 
				arg1 = NEB_arg1 << Get;
				arg2 = NEB_arg2 << Get;
				
				// initialize the result
				ResMat = {}; 
				// loop through each row
				For( i = 1, i <= nR, i++,
					ResMat[i] = {};
					// loop through each column getting values
					For( r = 1, r <= nC, r++,
						ResMat[i][r] = TB1[CheckBoxBox( r )] << get( i )
					);
				);
				// convert the list to a 2-d matrix
				ResMat = Matrix( ResMat );
				 	
				ResultMatrix = Matrix( ResMat );
				
				print(ResultMatrix);
			)// end of button box 
		)// end of H List Box 
	)// end of V List Box
); 
	
NW1 = New Window( "TestUI",
	V List Box(
		InputsLoadBasic;
		InputsUnloadBasic;
	)
);
Article Labels

    There are no labels assigned to this post.