So I do loop over the form and check "checked" value for all checkboxes. Every time I get "Unchecked" back even if the checkbox is checked on the form.
here is how i loop
public class FindAll
{
public IEnumerable<Control> GetAllChildren(Control root)
{
var stack = new Stack<Control>();
stack.Push(root);
while (stack.Any())
{
var next = stack.Pop();
foreach (Control child in next.Controls)
stack.Push(child);
yield return next;
}
}
}
and here how i determine checked state
public List<string> Checked()
{
List<string> checkedList = new List<string>();
var all = new FindAll();
foreach (var checkbox in all.GetAllChildren(tabPage4).OfType<CheckBox>())
{
checkedList.Add(checkbox.CheckState.ToString());
}
for (int i = 0; i < 22; i++)
{
MessageBox.Show(checkedList.ElementAt(i));
}
return checkedList;
}
no matter if i chech the checkboxes on the form while app is running. i always get "unchecked" value.
Aucun commentaire:
Enregistrer un commentaire