1
$\begingroup$

I am trying to write a function which creates a Grid which has no value in the starting and when some value is passed to it, it should show that value in that Grid dynamically. But it is not changing it dynamically.

The two user defined functions are

createGrid[rows_, column_] := (list = {}; 
  For[i = 1, i <= rows,i++, (individualColumns = {}; 
  For[j = 1, j <= column,j++, (Subscript[e,i, j]="";individualColumns = Append[individualColumns,Subscript[e,i, j]];)]; 
list = Append[list, individualColumns];)]; layoutGrid[list])

This createGrid function generates null values which is then passed to user defined function layoutGrid.

 layoutGrid[list_] := 
Panel[Grid[list, Background -> LightBlue, Spacings -> {0, 0}, ItemSize -> {0, 0},   Alignment -> {Center, Center}],ImageSize -> {780, 480}, Background -> LightBlue]

I am calling the createGrid function by passing 20 rows and 20 columns as arguments.

Dynamic[createGrid[20,20]]

It creates the Grid having 20 rows and 20 columns having no value.

In createGrid function, variable Subscript[e,i,j], i defines the row number and j defines the column number

After building the empty Grid,when I am assigning some value to Subscript[e,1,2] like

Subscript[e,1,2]=10;

It does not show in the Grid dynamically. Why?

$\endgroup$
4
$\begingroup$

You can do :

alist = ConstantArray["", {20, 20}];

Dynamic@Panel[ Grid[alist, Background -> LightBlue, Spacings -> {1, 1}, 
  ItemSize -> {0, 0}, Alignment -> {Center, Center}], 
  ImageSize -> {780, 480}, Background -> LightBlue]

alist[[1, 2]] = 10;
alist[[3]] = ConstantArray[3.14, {20}];
alist[[4, 2]] = 2.71;
alist[[4, 3]] = SpanFromLeft;
alist[[4, 4]] = 2.71;
alist[[4, 5]] = 2.71;

grid

$\endgroup$
  • $\begingroup$ Thank you alot!for your replyBut if I assign the SpanFromLeft to the alist[[1,2]] then spanning is not working $\endgroup$ – subbu Oct 5 '12 at 8:39
  • $\begingroup$ @subbu It seems to be working fine, please see edit. $\endgroup$ – b.gates.you.know.what Oct 5 '12 at 8:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.