Link to home
Start Free TrialLog in
Avatar of Pit76
Pit76Flag for Belgium

asked on

Clear all texboxes on a winform c#

Hi all,

I have a peice of code to clear all textboxes on a winform. This works fine but when I have a form with a control on it who can contain controls itself it doesn't work.

Can anyone tell me how to expand this so that it checks textboxes in controls? Like a form with tabpages wich has groupbox with controls in it.
Below my code.

Greetings
public static void ClearAllTextbox(Form frm)
        {
          foreach (Control ctrl in frm.Controls)
          {
            if (ctrl is TextBox || ctrl is RichTextBox)
            {
              if (ctrl.Text.Length > 0)
              {
                ctrl.Text = string.Empty;
              }
            }
          }
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pit76

ASKER

Hi guys,
I've split the points cos both of your solutions work for me. Thx guys!