Message Boards Message Boards

Use If within CheckboxBar?

GROUPS:
dynamic interactivity interface construction wolfram language

I want to make a "slectAll" and "slectNone" button in CheckboxBar,this is current method

DynamicModule[{x}, 
 First[{CheckboxBar[
    Dynamic[x], {1, 2, 3, 4 -> "SelectAll", 5 -> "SelectNone"}], 
   If[MemberQ[x, 4], x = {1, 2, 3}, If[MemberQ[x, 5], x = {}]]}]]

But it's seem the If don't work..

POSTED BY: zhu yude
Answer
17 days ago

Well, First from {CheckboxBar[ Dynamic[x], {1, 2, 3, 4 -> "SelectAll", 5 -> "SelectNone"}], If[MemberQ[x, 4], x = {1, 2, 3}, If[MemberQ[x, 5], x = {}]]} is just CheckboxBar[ Dynamic[x], {1, 2, 3, 4 -> "SelectAll", 5 -> "SelectNone"}]. But let's leave this aside.

CheckboxBar has some non trivial action behind so in this case the DynamicWrapper will be the most convenient:

DynamicModule[{x}
  , DynamicWrapper[
        CheckboxBar[ Dynamic[x], {1, 2, 3, 4 -> "SelectAll", 5 -> "SelectNone"}]
      , If[MemberQ[x, 4], x = {1, 2, 3}, If[MemberQ[x, 5], x = {}]]
    ]
]
POSTED BY: Kuba Podkalicki
Answer
17 days ago

Group Abstract Group Abstract