This code will set the checkboxes from a saved matrix of 1s and 0s.
// Set some random values in this matrix
saved_cbmat =
[ 1 0 0 1 0 0 0 0 0 0,
0 0 0 0 0 0 0 0 0 0,
0 1 0 0 0 0 0 0 0 0,
0 1 0 0 0 0 1 0 0 0,
0 1 0 1 0 0 1 0 1 0,
0 0 0 0 0 0 0 0 0 1,
0 0 0 0 0 0 0 0 1 1,
0 0 0 0 0 0 0 0 1 0,
0 0 0 0 0 0 0 0 1 0,
0 0 0 0 0 0 0 0 0 0];
n = 10; // # rows
m = 10; // # cols
a = 1::n;
// Create a list of empty text fields as checkbox labels
cb_list = {};
for (i = 1, i <= n, i++,
cb_list[i] = "";
);
cbmat = j(n, m, 0);
// Create the window
nw = new window("Test",
tb = table box(
ncb = number col box("", a),
),
okb = button box("OK",
for (i = 1, i <= m, i++,
for (k = 1, k <= n, k++,
cbmat[k, i] = cb[i] << get(k);
),
);
show(cbmat);
nw << close window;
),
);
// Create an array of checkbox columns
cb = {};
// Add the checkboxes
for (i = 1, i <= m, i++,
cb[i] = checkbox(cb_list);
cb[i] << set heading(char(i));
tb << append(cb[i]);
);
// Preload the checkboxes from the saved matrix
for (i = 1, i <= m, i++,
for (k = 1, k <= n, k++,
on_off = saved_cbmat[k, i];
cb[i] << set(k, on_off);
),
);