Pit76
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
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;
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I've split the points cos both of your solutions work for me. Thx guys!