locked
reloads form in c#

    Question

  • how to reload form after successful insertion
    i have a registration form and when i inserts data it should be reloaded and all the fields should reset like a form just initialized as default
    how to achiev this in VC# 2010
    Monday, August 06, 2012 1:06 PM

Answers

  • Hi,

    I think you have to write your own init function which clears the textboxes, comboboxes, etc.

    Monday, August 06, 2012 1:23 PM
  • try this

    this.formName_Load(this, null);


    Kapul

    Monday, August 06, 2012 5:00 PM
  • how to reload form after successful insertion
    i have a registration form and when i inserts data it should be reloaded and all the fields should reset like a form just initialized as default
    how to achiev this in VC# 2010

    Best would be (but still depeneds on some important facts) to clear all the control, or set their indexes to -1 (like comboBox`s selected index property).

    Create a common method which will do that, like:

    private void Register_Click()
    {
        //do the register code..
        //and then:
        ClearingControls();
    }
    
    private void ClearingControls()
    {
         foreach (TextBox tb in this.Controls.OfType<TextBox>())
             tb.Clear();
         foreach (ComboBox cb in this.Controls.OfType<ComboBox>())
             cb.SelectedIndex = -1;
    
         foreach (ListBox lb in this.Controls.OfType<ListBox>())
             lb.SelectedIndex = -1;
                //and so on...
    }

    Hope it helps,

    bye



    Mitja

    Monday, August 06, 2012 5:11 PM
  • try this

    this.formName_Load(this, null);


    Kapul

    how to write it my form name is cash but when i write this.Cash_Load no such function exists
    Tuesday, August 07, 2012 3:51 PM

All replies

  • Hi,

    I think you have to write your own init function which clears the textboxes, comboboxes, etc.

    Monday, August 06, 2012 1:23 PM
  • If you don't want to manually clear everything you can just close the old form and open up a new one, assuming the initialization of that form isn't prohibitive.
    Monday, August 06, 2012 4:17 PM
  • try this

    this.formName_Load(this, null);


    Kapul

    Monday, August 06, 2012 5:00 PM
  • how to reload form after successful insertion
    i have a registration form and when i inserts data it should be reloaded and all the fields should reset like a form just initialized as default
    how to achiev this in VC# 2010

    Best would be (but still depeneds on some important facts) to clear all the control, or set their indexes to -1 (like comboBox`s selected index property).

    Create a common method which will do that, like:

    private void Register_Click()
    {
        //do the register code..
        //and then:
        ClearingControls();
    }
    
    private void ClearingControls()
    {
         foreach (TextBox tb in this.Controls.OfType<TextBox>())
             tb.Clear();
         foreach (ComboBox cb in this.Controls.OfType<ComboBox>())
             cb.SelectedIndex = -1;
    
         foreach (ListBox lb in this.Controls.OfType<ListBox>())
             lb.SelectedIndex = -1;
                //and so on...
    }

    Hope it helps,

    bye



    Mitja

    Monday, August 06, 2012 5:11 PM
  • try this

    this.formName_Load(this, null);


    Kapul

    how to write it my form name is cash but when i write this.Cash_Load no such function exists
    Tuesday, August 07, 2012 3:51 PM
  • This is the Form Load Event Method of your Form to which you want to reload.

    Kapul

    Tuesday, August 07, 2012 4:47 PM
  • I thought of replying to this thread after reading thru the question twice, if you really wanted to RELOAD the form, you could try something like the one below:

    System.Diagnostics.Process.Start( Application.ExecutablePath); // to start new instance of application
    this.Close(); //to turn off current app

    The code shown above will start a new instance (process) of the application to work and close the existing one. however, if your objective was just to clear the values then stick on with what other forum members have suggested.


    Balaji Baskar
    http://codesupport.wordpress.com
    Click on "Vote As Helpful" and "Mark As Answer" if this has helped you.

    Wednesday, August 08, 2012 11:17 AM