Is it possible to iterate using foreach loop on multiple groupBox.
I have 6 GroupBox named as gBox1,gBox2,gBox3,gBox4,gBox5,gBox6 AND each gBox contain 21 ComboBox named as slot1,slot2,slot3,slot4,slot5.... so on out of which I want to select only 7 comboBoxes for operation.
For eaxmple if user enter 2 in textbox then from gBox1->cb15,slot1,slot2,slot3,slot4,slot5,slot6,slot7 and from gBox2->slot8,slot9,slot10,slot11,slot12,slot13 text of all comboBox should be stored in a string array.
Now problem is I am able to Iterate on ComboBox like this
if (no_of_period == 2)
{
if (duration == 1)
{
foreach (var comboBox in gBox2.Controls.OfType<ComboBox>().OrderBy(m => m.Name))
{
if (comboBox.Name.Substring(0, 4).Equals("slot"))
{
comboBox.Text = i.ToString("HH:mm");
}
}
i = i.AddMinutes(60);
foreach (var comboBox in gBox3.Controls.OfType<ComboBox>().OrderBy(m => m.Name))
{
if (comboBox.Name.Substring(0, 4).Equals("slot"))
{
comboBox.Text = i.ToString("HH:mm");
}
}
}
Now I have to write this code for all 6 gBox is there any way to automatically gBox should change... Something like this- NOT CORRECT CODE
foreach (var sgrpBox in batch_creation.ActiveForm.Controls.OfType<GroupBox>().OrderBy(g => g.Name))
{
string gname = null;
if (sgrpBox.Name.Substring(0, 4).Equals("gBox"))
{
gname = sgrpBox.Name.Substring(0, 4) + G;
foreach (var comboBox in ganme.Controls.OfType<ComboBox>().OrderBy(m => m.Name))
{.......