Question
How to Clear The Windows Form (User's input form and progress)
During processing of a PDF file (one record) I have many input fields on screen that the user needs to fill in. Once the automation starts, I show the progress with some other controls. There will be over 100 individual controls by the time this particular automation project is completed.
Question: Is there a way to clear or reset all the controls to their starting state before the next file is loaded? I am looking for an approach that we can easily re-use as we will have other RDA projects coming after this. Re-setting each control 1-by-1 would be manually intensive, prone to gaps, and not re-useable. Thanks.
***Edited by Moderator: Pallavi to update platform capability tags***
In the automation drag each control's Clear, ResetText method. or
try below code script by passing Form as input.
void ClearControls(Form)
{
foreach (Control c inForm.Controls)
{
if (c is ContainerControl)
ClearControl(c);
}
}
void ClearControl(Control c)
{
c.Text = string.Empty;
if(c is ComboBox)
{
((ComboBox) c).SelectedIndex = -1;
((ComboBox) c).Items.Clear();
}
foreach (Control child in c.Controls)
ClearControl(child);
}