# Setting CheckboxBar defaults under Manipulate

How is the default for the checkboxes created by CheckboxBar in a Manipulate set to be checked instead of unchecked? (The number of checkboxes may be variable.)

-
Would you please give an example of the code you are working on? –  Mr.Wizard Mar 20 at 15:14
Generally speaking, all controls are set to the initial value(s) of the variables, if any. –  Michael E2 Mar 20 at 15:16

You can specify an initial value to a variable captured by a Manipulate construct. In your particular case, you could do something like this:

Manipulate[Total[x], {{x, Range[5]}, Range[5], ControlType -> CheckboxBar}]


This creates a CheckboxBar control with five checkboxes all preset to the checked state. The values in the CheckboxBar do not need to be integers.

With[{zooList = {"Cow", "Walrus", "Zebra", "Lion"}},
Manipulate[
If[Length[x] === 0, "I want to see nothing at the zoo.",
StringJoin[{"I want to see a ", Riffle[x, ", "],
" at the zoo."}]], {{x, zooList}, zooList,
ControlType -> CheckboxBar}]]

-

Initialization for CheckboxBar works pretty much as for any type of control.

{{checkBoxes, initial-checked-values, ""}, value-list, ControlType -> CheckboxBar}]


For example,

Manipulate[Row[{"Boxes checked: ", Length@checkBoxes}],
{{checkBoxes, {1, 3}, ""}, {1, 2, 3, 4}, ControlType -> CheckboxBar}]


will produce the following initial state when evaluated.

-