Predefine Checkmarks of CheckboxList

0 votes
asked Jan 12, 2017 in Help by vrguy (120 points)
I want to predefine checkboxes to be able to represent the actual status of some variables. The appoach to edit the "selectedIndexes" did not work. What is the best way to achieve this?

bool[] options = new bool[] { true, false, false, false, false };
string[] showComponents = new string[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };

DialogCheckboxList myCheckboxlist = DialogManager.CreateCheckboxList();        
myCheckboxlist.Initialize(showComponents, OnCheckboxValidateClicked, "OK", "Show components", null, null, "Exit");
myCheckboxlist.selectedIndexes = options;
myCheckboxlist.Show();

1 Answer

0 votes
answered Jan 13, 2017 by admin (31,720 points)

Hello!

Well that's because you also need to add this:

for (int i = 0; i < myCheckboxlist.selectionItems.Count; i++)
{
    myCheckboxlist.selectionItems[i].itemCheckbox.toggle.isOn = options[i];
}

So the whole thing would be:

bool[] options = new bool[] { true, false, true, true, false };
string[] showComponents = new string[] { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };

DialogCheckboxList myCheckboxlist = DialogManager.CreateCheckboxList();        
myCheckboxlist.Initialize(showComponents, OnCheckboxValidateClicked, "OK", "Show components", null, null, "Exit");
myCheckboxlist.selectedIndexes = options;
for (int i = 0; i < myCheckboxlist.selectionItems.Count; i++)
{
	myCheckboxlist.selectionItems[i].itemCheckbox.toggle.isOn = options[i];
}
myCheckboxlist.Show();

Yes I know, this is not ideal and we should improve that :)

~ Yohan

Welcome to MaterialUI support! Ask us anything :)
...