Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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

share|improve this answer
    
Thank you alot!for your replyBut if I assign the SpanFromLeft to the alist[[1,2]] then spanning is not working –  subbu Oct 5 '12 at 8:39
    
@subbu It seems to be working fine, please see edit. –  b.gatessucks Oct 5 '12 at 8:51
    
Thanks. It is working. –  subbu Oct 5 '12 at 9:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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