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.

Background: In a module containing an outer / inner manipulate I select the key of data with a dropdownlist in the outer manipulate. Data is read and displayed in the inner manipulate for edit purposes. The outer manipulate contains buttons, one of which is a save button. I want to get the edited data back at that level so that it can be saved.

Consider the following simplified example:

  Manipulate[
   Column[{j,
   Manipulate[k, {k, 1, 5, 1}],
    Button["Check", Print[k]]
   }],
  {j, 1, 10, 1}]

the question then becomes: "What is the best way to get the variable k scoped to the first / outer manipulate" ?

share|improve this question
add comment

2 Answers

up vote 7 down vote accepted

How about this:

DynamicModule[{k},
  Manipulate[
   Column[{j,
     Manipulate[k, {k, 1, 5, 1}, LocalizeVariables -> False],
     Button["Check", Print[k]]
   }],
   {j, 1, 10, 1}]
]
share|improve this answer
    
Just out of curiosity, is there a particular reason why you put the DynamicModule on the outside of the outer Manipulate? –  Heike Apr 18 '12 at 16:22
    
@Heike It is not strictly necessary, but in this way, we don't generate a new symbol/variable every time when external Manipulate recomputes its body. This is the same logic as when we use external Module to create persistent local variables, as for example I discussed here. –  Leonid Shifrin Apr 18 '12 at 17:02
add comment

Using LocalizeVariables -> False as in Leonid's answer is probably the easiest, but the downside is that it makes all controls in the inner Manipulate visible to the outer Manipulate and beyond. If you have multiple controls in the inner Manipulate but you want the outer Manipulate to only see some of them to be visible to the outer Manipulate you could also do something like

Manipulate[
 DynamicModule[{k1}, 
  Column[{j, Manipulate[k1 = k, {k, 1, 5, 1}], 
    Button["Check", Print[k1]]}]], {j, 1, 10, 1}]
share|improve this answer
    
Heike, I have accepted Leonid's answer because what you refer to as a downside works out rather advantageous in my code. –  ndroock1 Apr 18 '12 at 18:21
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.