# Can I create a dynamic number of rows in TabView through an iteration?

I have written code, with the help of stackoverflow of course, and I want to make it user friendly so that other people in my lab can use it. I'm playing with DialogCreate and similar functions. I want to do something like this so far:

   CreateDialog[TabView[{
"General" ->
Column[{
Row[{TextCell["Project Name:"], InputField[Dynamic[Project]]}],
Row[{TextCell["Number of Wells:"], InputField[Dynamic[num]],
Button["Set", DialogReturn[num]]}]}],
"Row Selection" ->
Column[{Do[
Row[TextCell["Well " <> ToString[i] <> ":"],
FileNameSetter[Dynamic[Evaluate[Symbol["w" <> ToString[i]]]],
"Open"]], {i, 1, num}]}]}, ControlPlacement -> Left]
]


I want to dynamically create more rows based on the input of "Number of Wells" within the same dialogbox but in a different tab. Is anything like this possible or some sort of alternative?

-
Code doesn't run as posted. Looks like you may need to define "Project". Hard to tell without the example running. – Jagra Aug 29 '12 at 20:07
Check the answer below, it worked well. :) – tquarton Aug 30 '12 at 0:06

Does the following work as needed?

CreateDialog[
TabView[
{"General" ->
Column[{Row[{"Project Name:", InputField[Dynamic[project]]}],
Row[{"Number Of Wells:", InputField[Dynamic[num]],
Button["Set", DialogReturn[num]]}]}],
"Row Selection" ->
Dynamic@Column[
Table[Row[{"Well " <> ToString[i] <> ":",
FileNameSetter[Dynamic[Evaluate[Symbol["w" <> ToString[i]]]],
"Open"]}], {i, 1, num}]]},
ControlPlacement -> Left]]


Update: There are two problems in the original code:

First, regarding the use of Do, unless an explicit Return is used, the value returned by Do is Null. Please see the docs on Do and the tutorial Loops and control structures. For example

 t = 2; Do[t = 1 + k t, {k, 1, 2}]


does the calculation to change the value of t but does not return anything. You need to explicitly call the new value of t to see the effect of what happened inside Do:

t = 2; Do[t = 1 + k t, {k, 1, 2}];t
(* which gives the result: 7 *)


So, to get your code working with Do, you need to do something like:

"Row Selection" ->
Dynamic@Column[tt = {};
Do[AppendTo[tt, Row[{"Well " <> ToString[i] <> ":",
FileNameSetter[Dynamic[Evaluate[Symbol["w" <> ToString[i]]]],
"Open"]}]],
{i, 1, num}]; tt]


which, of course, is not as clean as the alternative with Table[...].

Second, regarding why Dynamic[Column[ ...]] is needed please see the tutorial Introduction to Dynamic, in particular, the section Where Should Dynamic Be Placed in an Expression?

By the way, @ is short form of Prefix, and f@x is an alternative syntax for f[x], that is, Dynamic@Column[.....] is the same as Dynamic[Column[...]].

-
Perfect! Thanks so much kguler. – tquarton Aug 29 '12 at 23:01
So can you explain what adding the @ does that makes this work? I'd like to learn how you knew how to do that. – tquarton Aug 29 '12 at 23:15
@tquarton, thank you for the accept. Please see the update with links to useful material. – kglr Aug 30 '12 at 8:31