user2088808
user2088808

Reputation: 25

Reset Controls Within a Panel to their Starting States

I suspect that there is a simple answer to this, but finding a straight answer is providing tricky.

I have a set of textboxes/DateTime pickers/RadioButtons, ect within a panel within a form. I want make a button to clear these fields to their initial state, but having to go in and individually code commands to reset/clear these fields seems excessive. Is there a way to collectively fields within a form/panel?

If there is a way to reset em masse, how could one direct it to be localized to a single tab or panel?

Upvotes: 0

Views: 690

Answers (1)

andy
andy

Reputation: 6079

You need to use FOREACH for it.....

like

foreach (Control item in panel1.Controls)
{
  if (item is TextBox || item is RadioButton || item is DateTimePicker)
  {
    item.Text = "Initial Value";
   }
}

OR

if (item.GetType() == typeof(TextBox) || item.GetType() == typeof(RadioButton)   
|| item.GetType() == typeof(DateTimePicker))
{
  item.Text = "Initial Value";
}

Upvotes: 4

Related Questions