6
Reply

Windows Forms - Iterating through controls on a form

Ask a question
Daniel

Daniel

17y
3.1k
1
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)