I have inherited the new save close buttons from base form to all the forms. I write the code in the base form to clear all the controls when new button clicked.
foreach (Control ctrl in cc)
{
if (ctrl.GetType() == typeof(TextBox))
ctrl.Text = "";
else if (ctrl.GetType() == typeof(ComboBox))
{
ComboBox cb = ctrl as ComboBox;
cb.SelectedIndex = -1;
cb.Text = "";
}
}
This code will clear all the TextBoxes and ComboBoxes. Now I want to focus the first TextBox after clicking the new button. Code must write in base form to focus first control in all the inherited forms.
You may get the first
TextBoxfrom the Control Collection on the base form using LINQ FirstOrDefault. Later you can call its Focus method.