Daniel

Daniel

  • NA
  • 66
  • 0

Windows Forms - Iterating through controls on a form

Jun 14 2007 2:07 PM
I have a form with many groupboxes (18) and within each groupbox are controls (textboxes and checkboxes). When the user clicks the "NEW" button, I want to clear all controls on the form for data entry. I figured I would generically iterate through all the controls on the form and clear the information accordingly (set textbox.text = "" or checkbox.checked == false). I can get to all the groupboxes but can figure out how to iterate the controls within each groupbox. Here is my psuedo code: foreach (Control c in this.Controls) { //check for a groupbox if (c is GroupBox) { } }

Answers (6)