3

I am storing the values from xlData to the result in a Grid form. I want when I change any of the value in any of the InputFields, it should show the change dynamically when I evaluate result again. I have to use this result variable again in my code. How can I do this?

   result = {};   
   xlData = {{1, "a", "b", "c"}, {2, "d", "e", "f"}};
   For[i = 1, i <= Length[xlData], i++,
    (iniRow = {};
     For[j = 1, j <= Length[xlData[[i]]], j++,
      If[xlData[[i, j]] != "",     
      (iniRow =Append[iniRow,InputField[xlData[[i, j]], FieldSize -> {4, 1}]];
      )]];                    
        result = Append[result, iniRow];)]
       Grid[result]                                                          
Jennifer
  • 953
  • 4
  • 16

1 Answers1

7

Your code can be made much simpler as such...

xlData = {{1, "a", "b", "c"}, {2, "d", "e", "f"}};
Grid@Table[
   With[{i = i, j = j}, 
   InputField[Dynamic[xlData[[i, j]]], FieldSize -> {4, 1}]], {i, 1, Length[xlData]},
   {j,1,Length[xlData[[1]]]}]

As you change values, it can be monitored by:

Dynamic[xlData]

As written, the code keeps xlData with a List head at all times.

kale
  • 10,922
  • 1
  • 32
  • 69