4
$\begingroup$

I want to use a checkbox to invert the current checkboxbar selection, the code now basically works, but I hope that when the checkboxbar is all selected or not, the status of the first checkbox will respond correctly.

DynamicModule[{x, y},
 x = {a, b, c, d};
 y = x;
 Column[{
   Row[{"first", Spacer[16], 
     Dynamic@Checkbox[Dynamic[y], {Complement[x, y], x}]}], 
   Row[{"second", Spacer[6], Dynamic[CheckboxBar[Dynamic[y], x]]}],
   Dynamic[{x, y, Complement[x, y]}]
   }]
 ]

current state

enter image description here enter image description here

Correct state
enter image description here enter image description here

$\endgroup$
1
$\begingroup$

This is probably what you want to do :

 DynamicModule[{x, y, inverted}, x = {a, b, c, d};
 y = x;
 inverted = False;
 Column[{
   Row[{"first", Spacer[16], 
     Checkbox[
      Dynamic[inverted, (y = Complement[x, y]; inverted = #) &]]}],
   Row[{"second", Spacer[6], CheckboxBar[Dynamic[y], x]}]}]]

enter image description here

$\endgroup$

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.