.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh

Home >> Code Snippets >> Windows Form Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

How to reset ALL the controls in a form to the default values

Posted By:Jean Paul       Posted Date: September 29, 2010    Points: 10    Category: Windows Form Controls    URL: http://www.dotnetspark.com  

Eg: TextBoxes to empty, ComboBox to index -1, Checkboxes to false Usage: ResetControls(form);

public void ResetControls(Control parentControl) { foreach (Control control in parentControl.Controls) { if (control is TextBox) (control as TextBox).Text = String.Empty; if (control is CheckBox) (control as CheckBox).Checked = false; if (control is ComboBox) (control as ComboBox).SelectedIndex = -1;

// Do same for controls having children if (control.HasChildren) ResetControls(control); } }


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend