Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Reload Form1 when Form2 ShowDialog like?

Reload Form1 when Form2 ShowDialog like?

Scheduled Pinned Locked Moved C#
helpdatabasequestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nhanlaptrinh
    wrote on last edited by
    #1

    Hi all! I asked for the issue as follows: I can program in C Windows Form. I have two Form: Form1 and Form2. Form1 has a datagrid and a button1. In the DataGrid displays the user with 2 column username and password. Form2 has two TextBox is txtTenDangNhap and txtMatKhau, and a Button btnLuu. In Form1: When Form1 loads the program will load a list of accounts available in the database to the DataGrid. When you click Button1, then Form2 will appear in the form of ShowDialog. (Form2 f2 = new Form2 (); f2. ShowDialog ()) (Note: Form1 is still not closed) On Form2: When pressing Button btnLuu, the new account will be saved to the database and Form2 will close. When Form2 is closed on Form1 DataGrid will load the data with the new account added. For help yourself with!

    R 1 Reply Last reply
    0
    • N nhanlaptrinh

      Hi all! I asked for the issue as follows: I can program in C Windows Form. I have two Form: Form1 and Form2. Form1 has a datagrid and a button1. In the DataGrid displays the user with 2 column username and password. Form2 has two TextBox is txtTenDangNhap and txtMatKhau, and a Button btnLuu. In Form1: When Form1 loads the program will load a list of accounts available in the database to the DataGrid. When you click Button1, then Form2 will appear in the form of ShowDialog. (Form2 f2 = new Form2 (); f2. ShowDialog ()) (Note: Form1 is still not closed) On Form2: When pressing Button btnLuu, the new account will be saved to the database and Form2 will close. When Form2 is closed on Form1 DataGrid will load the data with the new account added. For help yourself with!

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      Do you have a specific question you need help with? /ravi

      My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

      N 1 Reply Last reply
      0
      • R Ravi Bhavnani

        Do you have a specific question you need help with? /ravi

        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

        N Offline
        N Offline
        nhanlaptrinh
        wrote on last edited by
        #3

        I have done, but also want to address up on this issue and for all, who needs it to use: In Form1: Set the button code below in the form1

        Form2 f = new Form2();
        if (f.ShowDialog() == DialogResult.OK)
        {

                }
                else
                {
                    //Load the list that you want
                }
        

        In form2: Set the button code below in the form 2

        this.DialogResult = DialogResult.Cancel;

        L OriginalGriffO 2 Replies Last reply
        0
        • N nhanlaptrinh

          I have done, but also want to address up on this issue and for all, who needs it to use: In Form1: Set the button code below in the form1

          Form2 f = new Form2();
          if (f.ShowDialog() == DialogResult.OK)
          {

                  }
                  else
                  {
                      //Load the list that you want
                  }
          

          In form2: Set the button code below in the form 2

          this.DialogResult = DialogResult.Cancel;

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          If a dialog wants the caller Form to perform some action, then it normally sets DialogResult to one of the predefined values (but not None nor Cancel), and the caller tests for that value. Using Cancel and putting the action in the else part of the test is extremely weird. Were you sober when you wrote this? :)

          Luc Pattyn [My Articles] Nil Volentibus Arduum

          1 Reply Last reply
          0
          • N nhanlaptrinh

            I have done, but also want to address up on this issue and for all, who needs it to use: In Form1: Set the button code below in the form1

            Form2 f = new Form2();
            if (f.ShowDialog() == DialogResult.OK)
            {

                    }
                    else
                    {
                        //Load the list that you want
                    }
            

            In form2: Set the button code below in the form 2

            this.DialogResult = DialogResult.Cancel;

            OriginalGriffO Offline
            OriginalGriffO Offline
            OriginalGriff
            wrote on last edited by
            #5

            The "proper" way to do this is to provide two buttons in Form2, and set their properties appropriately. The "OK" button has the DialogResult set to Dialogresult.OK The "Cancel" button has the DialogResult set to Dialogresult.Cancel The Form has its AcceptButton property set to the OK button, and is CancelButton set to the Cancel Button. The framework will then handle the buttons without any event handlers being necessary. These properties can be set at design time. In fact, I use a OK/Cancel button so often, I have made a VS Template to create it automatically - there is a Tip here which describes how to do it: Create Visual Studio forms for items you frequently use[^]

            Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

            "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
            "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups