i found it is possible to validate checkboxes is selected or not by linq.
i got the code like
btnAgree.Enabled = (from chkbox in Controls.OfType<CheckBox>() select chkbox).Count(b => b.Checked) >= 2;
but my scenario is like i have many check boxes on my win form but i want to check any check boxes inside my group box is selected by LINQ. is it possible but i found no way still. please help me with code.
i got a little code which is bit similar. the code as follows
public static IEnumerable<T> AllControls<T>(this Control startingPoint) where T : Control
{
bool hit = startingPoint is T;
if (hit)
{
yield return startingPoint as T;
}
foreach (var child in startingPoint.Controls.Cast<Control>())
{
foreach (var item in AllControls<T>(child))
{
yield return item;
}
}
}
var checkboxes = control.AllControls<CheckBox>();
var checkedBoxes = control.AllControls<CheckBox>().Where(c => c.Checked);
but how to customize this code that it will work with group box where my all check box is located. please guide. another issue is i am using c# v2.0. thanks
You’re checking the controls of the form.