父窗体Form1 子窗体Form2 Form1中有一个datagridview控件和一添加按钮,

Form2中有一个Text控件和一个保存按钮 要求点击Form1窗体上的添加按钮,弹出Form2,

再text里面输入内容,点击保存自动关闭Form2,刷新Form1中datagridview中的数据

From1中: 

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

From2中:

<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 ('" + textBox1.Text.ToString() + "')"; 
 
      conn.Open(); 
 
      SqlCommand myCmd = new SqlCommand(sql, conn); 
 
      myCmd.ExecuteNonQuery(); 
 
      conn.Close(); 
      this.DialogResult = DialogResult.OK; 
      MessageBox.Show("添加成功"); 
      this.Close(); 
       
    } 


以上这篇winform c#中子窗体关闭刷新父窗体的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持悠悠之家。

点赞(55)

评论列表共有 0 条评论

立即
投稿
返回
顶部