Home > Backend Development > C#.Net Tutorial > Detailed explanation of the sample code for closing the subform and refreshing the parent form in winform c#

Detailed explanation of the sample code for closing the subform and refreshing the parent form in winform c#

黄舟
Release: 2017-03-21 11:43:38
Original
2472 people have browsed it

The following editor will bring you an example of closing a subform and refreshing the parent form in winform c#. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.

The parent form Form1 and the child form Form2 have a datagridview control and an add button in Form1.

There is a Text control and a save button in Form2. Requirements Click the Add button on the Form1 form to pop up Form2, enter

in the text, click Save to automatically close Form2, and refresh the data in the datagridview in Form1

From1 Medium:

private void button3_Click(object sender, EventArgs e) 
    { 
      Form2 f2 = new Form2(); 
      f2.ShowDialog(); 
      if (f2.DialogResult == DialogResult.OK) 
      { 
        this.datagridBind();//重新绑定 
      } 
       
    }
Copy after login

From2 Medium:

<BR><BR>private void button1_Click(object sender, EventArgs e) 
    { 
      string strConn = "server=.;database=filesSync;uid=sa;pwd=123"; 
 
      SqlConnection conn = new SqlConnection(strConn); 
 
      string sql = "insert into asyncFileList values (&#39;" + textBox1.Text.ToString() + "&#39;)"; 
 
      conn.Open(); 
 
      SqlCommand myCmd = new SqlCommand(sql, conn); 
 
      myCmd.ExecuteNonQuery(); 
 
      conn.Close(); 
      this.DialogResult = DialogResult.OK; 
      MessageBox.Show("添加成功"); 
      this.Close(); 
       
    }
Copy after login

The above is the detailed content of Detailed explanation of the sample code for closing the subform and refreshing the parent form in winform c#. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template