c# - Groupbox foreach not finding all textboxes -


i trying find textbox have entered information on form , make rest of textboxes within form blanked out , locked no information can entered them.

the problem when run code , debug. not seem finding textboxes on form when looping through them.

i have tried change of information in foreach trying find if groupbox name.equals , if items within groupbox equal text. assume have made mistake foreach statements.

below code.

 foreach (control c in this.controls)             {                 if (c groupbox)                      foreach (control t in this.controls)                     {                         if (t textbox)                         {                             {                                 if (t.text != string.empty && t.name.equals("txtlotno"))                                 {                                     txtheads.enabled = false;                                     txtheads.backcolor = color.lightgray;                                     groupboxheads.backcolor = color.lightslategray;                                     txtrisersgood.enabled = false;                                     txtrisersgood.backcolor = color.lightgray;                                     groupboxrisers.backcolor = color.lightslategray;                                 }                                  else if (t.text != string.empty && t.name.equals("txtvingot"))                                 {                                     txtheads.enabled = false;                                     txtheads.backcolor = color.lightgray;                                     groupboxheads.backcolor = color.lightslategray;                                     txtrisersgood.enabled = false;                                     txtrisersgood.backcolor = color.lightgray;                                     groupboxrisers.backcolor = color.lightslategray;                                 }                                 else if (t.text != string.empty && t.name.equals("txtheads"))                                 {                                     txtvingot.enabled = false;                                     txtvingot.backcolor = color.lightgray;                                     txtlotno.enabled = false;                                     txtlotno.backcolor = color.lightgray;                                     groupboxingot.backcolor = color.lightslategray;                                     txtrisersgood.enabled = false;                                     txtrisersgood.backcolor = color.lightgray;                                     groupboxrisers.backcolor = color.lightslategray;                                 }                                 else if (t.text != string.empty && t.name.equals("txtrisersgood"))                                 {                                     txtvingot.enabled = false;                                     txtvingot.backcolor = color.lightgray;                                     txtlotno.enabled = false;                                     txtlotno.backcolor = color.lightgray;                                     groupboxheads.backcolor = color.lightslategray;                                     txtheads.enabled = false;                                     txtheads.backcolor = color.lightgray;                                     groupboxingot.backcolor = color.lightslategray;                                 }                             }                         }                     }             } 

there simple error in loop initialization

foreach (control c in this.controls) {      if (c groupbox)      {         foreach (control t in c.controls)         {           ...... 

the second foreach should work on controls of groupbox not again on this.controls.
of course, these loops works textboxes contained in groupbox. if have textbox outside of groupbox code not find them-

however, why need loop?
change finite number of textboxes, access textboxes directly

 if (txtlotno.text != string.empty)  {      txtheads.enabled = false;      txtheads.backcolor = color.lightgray;      groupboxheads.backcolor = color.lightslategray;      txtrisersgood.enabled = false;      txtrisersgood.backcolor = color.lightgray;      groupboxrisers.backcolor = color.lightslategray;  }  .... , on the other 3 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

What is the difference between data design and data model(ERD) -

ios - Can NSManagedObject conform to NSCoding -