更新数据后DataGridview不重新加载/刷新?

时间:2017-10-16 18:01:45

标签: c# winforms

当我关闭表单(Form1)而不是它的make记录重复时,我没有刷新datagridview,我有两个表单,双击gridview控件转到form1,在更新数据后它不会更改gridview上的记录我必须重新启动程序来检查更改,我调用Gridviewload(); showstudentinfo函数中的方法,通过关闭form1,它更新了我在教程中看到的记录,不知道程序中的问题。

DataTable dt = new DataTable();
private void DetailsForm_Load(object sender, EventArgs e)
{
    GridViewLoad();
}

private void GridViewLoad()
{
    dataGridView1.DataSource = GetDeatilsList();
}
private DataTable GetDeatilsList()
{
    string constring = ConfigurationManager.ConnectionStrings["dbx"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constring))
    {
        using (SqlCommand cmd = new SqlCommand("usp_GetallRecords",con))
        {
            cmd.CommandType = CommandType.StoredProcedure;
            con.Open();
             SqlDataReader rdr = cmd.ExecuteReader();
             dt.Load(rdr);
        }
    }
   return dt;
}

private void dataGridView1_DoubleClick(object sender, EventArgs e)
{
    int rowtoUpdate = dataGridView1.Rows.GetFirstRow(DataGridViewElementStates.Selected);
    int studentId = Convert.ToInt16(dataGridView1.Rows[rowtoUpdate].Cells["ID"].Value);
    showstudentinfo(studentId, true);
}

private void showstudentinfo(int studentid, bool isupdate)
{
    Form1 sti = new Form1();
    sti.StudentID = studentid;
    sti.ISupdate = isupdate;
    sti.ShowDialog();
    GridViewLoad();
}

0 个答案:

没有答案