Detailed WinForm C # subform Off Refresh the sample code for the parent form

Source: Internet
Author: User
Here is a small series to bring you an article WinForm C # The subform closes the instance of the parent form. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.

The parent Form Form1 Subform Form2 Form1 has a DataGridView control and an Add button,

Form2 has a text control and a save button that asks for a click on the Add button on the Form1 form, pops up Form2,

Then text inside the input content, click Save to automatically close Form2, refresh the data in the Form1 DataGridView

In From1:

private void Button3_Click (object sender, EventArgs e)     {       Form2 F2 = new Form2 ();       F2. ShowDialog ();       if (F2. DialogResult = = DialogResult.OK)       {         this.datagridbind ();//Rebind       }            }

In From2:

<br><br>private void Button1_Click (object sender, EventArgs e) {string s Trconn = "server=.;        Database=filessync;uid=sa;pwd=123 ";        SqlConnection conn = new SqlConnection (strconn);        String sql = "INSERT into asyncfilelist values ('" + textBox1.Text.ToString () + "')"; Conn.        Open ();        SqlCommand mycmd = new SqlCommand (SQL, conn);        Mycmd.executenonquery (); Conn.       Close (); This.       DialogResult = DialogResult.OK;       MessageBox.Show ("add success"); This.            Close (); }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.