Click here to Skip to main content
Sign Up to vote bad
good
See more: C#4.0.NET4
Hi guy i have a form that has alot of controls which includes Textboxes, Each text boxes has a default value. Is the any way i can reload the form without closing it while retianing my textboxes default values.. Thanks
Posted 8-Sep-12 19:37pm


2 solutions

Hi ,
Check this
You can store the values in load then when you need it you can get it back
Hope it help .
 
List<string> lst = new List<string>();
private void Form1_Load(object sender, EventArgs e)
{
    foreach (Control ctrl in this.Controls)
    {
        if (ctrl is TextBox)
        {
            lst.Add(((TextBox)ctrl).Text);
        }
    }
}
 
private void button1_Click(object sender, EventArgs e)
{
    int i = 0;
    foreach (Control ctrl in this.Controls)
    {
        if (ctrl is TextBox)
        {
 
            ((TextBox)ctrl).Text = lst[i];
            i++;
        }
    }
}
 
Best Regards
M.Mitwalli
  Permalink  
If your Form is the Start up Form you can use:
Application.Restart();
otherwise there is no method for do that.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Christian Graus 477
1 Ron Beyer 316
2 samadhan_kshirsagar 269
3 Tadit Dash 243
4 OriginalGriff 181
0 Sergey Alexandrovich Kryukov 7,061
1 Prasad_Kulkarni 3,830
2 OriginalGriff 3,620
3 _Amy 3,370
4 CPallini 3,074


Advertise | Privacy | Mobile
Web04 | 2.6.130619.1 | Last Updated 9 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid