cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
uday_guntupalli
Level VIII

How to index into a table box of check boxes

All, 
      I have a m by n Table box of check boxes. I am wondering, how I can set some of them selected. 

     

 

          LB_b = Lineup Box(N Col(1)); 
	  nR = 10;
	  nC = 10;
	  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 ) ) ) )
		 );				
	  LB_b << Append(TB1);
	  
	  T = New Window("Test",TB1);

        When I look at the tree structure, I wonder why I am unable to access the elements. I tried  something like the following  with no luck. Also, the goal is not to be able to select a column of check boxes, but a single checkbox in the matrix. 

 

        

TB1["CheckBoxBox(1)"] << select ; 

 

Best
Uday
1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: How to index into a table box of check boxes

This code will set the checkboxes from a saved matrix of 1s and 0s.

// Set some random values in this matrix
saved_cbmat = 
[	1 0 0 1 0 0 0 0 0 0, 
	0 0 0 0 0 0 0 0 0 0, 
	0 1 0 0 0 0 0 0 0 0, 
	0 1 0 0 0 0 1 0 0 0, 
	0 1 0 1 0 0 1 0 1 0, 
	0 0 0 0 0 0 0 0 0 1, 
	0 0 0 0 0 0 0 0 1 1, 
	0 0 0 0 0 0 0 0 1 0, 
	0 0 0 0 0 0 0 0 1 0, 
	0 0 0 0 0 0 0 0 0 0];

n = 10;		// # rows
m = 10;		// # cols
a = 1::n;

// Create a list of empty text fields as checkbox labels
cb_list = {};
for (i = 1, i <= n, i++,
	cb_list[i] = "";
);


cbmat = j(n, m, 0);
// Create the window
nw = new window("Test",
	tb = table box(
		ncb = number col box("", a),
	),
	okb = button box("OK",
		for (i = 1, i <= m, i++,
			for (k = 1, k <= n, k++,
				cbmat[k, i] = cb[i] << get(k);
			),
		);
		show(cbmat);
		nw << close window;
	),
);

// Create an array of checkbox columns
cb = {};
// Add the checkboxes
for (i = 1, i <= m, i++,
	cb[i] = checkbox(cb_list);
	cb[i] << set heading(char(i));
	tb << append(cb[i]);
);

// Preload the checkboxes from the saved matrix
for (i = 1, i <= m, i++,
	for (k = 1, k <= n, k++,
		on_off = saved_cbmat[k, i];
		cb[i] << set(k, on_off);
	),
);

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: How to index into a table box of check boxes

You have 2 reference issues with

TB1["CheckBoxBox(1)"] << select ; 

The first is that 

TB1["CheckBoxBox(1)"]

is looking for an Outline Box with the title "CheckBoxBox()".  That is, you have placed "CheckBoxBox()" in quotes, and there for it is not looking for a CheckBoxBox() object, it is looking for an object with the title "CheckBoxBox(1)".  

Secondly, 

<< Select

is not a message that CheckBoxBox() has available to it.  

TB1[CheckBoxBox(1)] <<  get selected ; 

would be what you want, except for the fact that << get selected returns the string values for each of the check boxes selected, and since all of your string values for your check boxes are set to " ", that will be all you will be returned. So what you will need to do is to loop through each of the check boxes, and find the values. Here is a simple example

For( c = 1, c <= 10, c++,
	For( r = 1, r <= 10, r++,
		If( T[CheckBoxBox( c )] << get( r ) == 1,
			Show( c, r )
		)
	)
)
Jim
pmroz
Super User

Re: How to index into a table box of check boxes

Here's a way to do what you need:

n = 10;		// # rows
m = 10;		// # cols
a = 1::n;

// Create a list of empty text fields as checkbox labels
cb_list = {};
for (i = 1, i <= n, i++,
	cb_list[i] = "";
);


cbmat = j(n, m, 0);
// Create the window
nw = new window("Test",
	tb = table box(
		ncb = number col box("", a),
	),
	okb = button box("OK",
		for (i = 1, i <= m, i++,
			for (k = 1, k <= n, k++,
				cbmat[k, i] = cb[i] << get(k);
			),
		);
		show(cbmat);
		nw << close window;
	),
);

// Create an array of checkbox columns
cb = {};
// Add the checkboxes
for (i = 1, i <= m, i++,
	cb[i] = checkbox(cb_list);
	cb[i] << set heading(char(i));
	tb << append(cb[i]);
);

checkbox_matrix.png

cbmat = 
[	1 0 0 0 0 0 0 0 0 0, 
	1 0 0 0 0 0 0 0 0 0, 
	1 0 1 0 0 0 0 0 0 0, 
	0 0 1 0 0 0 0 0 0 0, 
	0 0 1 0 1 0 0 0 0 0, 
	0 0 0 0 1 0 1 0 0 0, 
	0 0 0 0 0 0 1 0 0 0, 
	0 0 0 0 0 0 1 0 0 0, 
	0 0 0 0 0 0 0 0 0 0, 
	0 0 0 0 0 0 0 0 0 0];
uday_guntupalli
Level VIII

Re: How to index into a table box of check boxes

@pmroz  and @txnelson ,
        Thank you for your responses. However, if I may, I think the primary part of my question that is, how do I set them to selected(My bad - I should have asked checked) doesn't seem to have been addressed. Could either of you guide me as to how I can check any of the checkboxes ? 

         I think @pmroz  's response provides a way to index to the checkbox, but I think it references them by column, not so much by each individual check box. I will try and illustrate in a little more detail what I seek: 

         The snippet I posted gives me a matrix of selectable checkboxes like so: 

 

image.png

         Now, should a user make his selection, I am able to unload the selection using the following: 

 

 

NW = New Window("Test",
					VLB0 = V List Box(Align(center),
									  LB_b
									 )
			   ); 
VLB0 << Append(
				H List Box(
								BB_TargetMatrix = Button Box( "OK", 
																																															
																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 )
																		   );	
																   );	
																ResMat = Matrix( ResMat );
																																								
															)// end of button box 
							 )// end of H List Box 
			  );

image.png

 

     

           However, I would like to know how I can the table box with some of the checkboxes pre-checked. I have a matrix the same size as the table box, which I would like to use to set the checkboxes checked. 

 

 

 

Best
Uday
pmroz
Super User

Re: How to index into a table box of check boxes

This code will set the checkboxes from a saved matrix of 1s and 0s.

// Set some random values in this matrix
saved_cbmat = 
[	1 0 0 1 0 0 0 0 0 0, 
	0 0 0 0 0 0 0 0 0 0, 
	0 1 0 0 0 0 0 0 0 0, 
	0 1 0 0 0 0 1 0 0 0, 
	0 1 0 1 0 0 1 0 1 0, 
	0 0 0 0 0 0 0 0 0 1, 
	0 0 0 0 0 0 0 0 1 1, 
	0 0 0 0 0 0 0 0 1 0, 
	0 0 0 0 0 0 0 0 1 0, 
	0 0 0 0 0 0 0 0 0 0];

n = 10;		// # rows
m = 10;		// # cols
a = 1::n;

// Create a list of empty text fields as checkbox labels
cb_list = {};
for (i = 1, i <= n, i++,
	cb_list[i] = "";
);


cbmat = j(n, m, 0);
// Create the window
nw = new window("Test",
	tb = table box(
		ncb = number col box("", a),
	),
	okb = button box("OK",
		for (i = 1, i <= m, i++,
			for (k = 1, k <= n, k++,
				cbmat[k, i] = cb[i] << get(k);
			),
		);
		show(cbmat);
		nw << close window;
	),
);

// Create an array of checkbox columns
cb = {};
// Add the checkboxes
for (i = 1, i <= m, i++,
	cb[i] = checkbox(cb_list);
	cb[i] << set heading(char(i));
	tb << append(cb[i]);
);

// Preload the checkboxes from the saved matrix
for (i = 1, i <= m, i++,
	for (k = 1, k <= n, k++,
		on_off = saved_cbmat[k, i];
		cb[i] << set(k, on_off);
	),
);