Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 Group box
Hi All
 
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 (help I got from code project for 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))
             {.......
 
Need guidance
Regards to all
Posted 25-May-13 5:30am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try a simple loop like this -
foreach (Control c in this.Controls)
{
   if(c is GroupBox)
   {
     // Do stuff here ;
   }
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 25 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100