Message Boards Message Boards

0
|
5442 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

Use If within CheckboxBar?

Posted 7 years ago

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: Yode Japhe

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
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract