Reset All Controls in GroupBox

Using this method you can reset all controls in windows form in GroupBox and save time for writing code to reset all controls individually.

Code for Reset Controls

void ResetAll(GroupBox gbox)

{

        foreach (Control ctrl in gbox.Controls)

        {

            if (ctrl is TextBox)

            {

                TextBox textBox = (TextBox)ctrl;

                textBox.Text = null;

            }

            if (ctrl is ComboBox)

            {

                ComboBox comboBox = (ComboBox)ctrl;

                comboBox.SelectedIndex = -1;

            }

            if (ctrl is CheckBox)

            {

                CheckBox checkBox = (CheckBox)ctrl;

                checkBox.Checked = false;

            }

            if (ctrl is RadioButton)

            {

                RadioButton radioButton = (RadioButton)ctrl;

                radioButton.Checked = false;

            }

            if (ctrl is ListBox)

            {

                ListBox listBox = (ListBox)ctrl;

                listBox.ClearSelected();

            }

        }

 }

I hope this article will helpful for you.