Search code examples
c#winformsevent-handlingformclosing

C# - Binding FormClosing event to cause Form refresh


I am having some difficulty getting a form to refresh when another form is closed. This is what I have so far, but it doesn't seem to trigger the refresh. I am very to new to programming, so any assistance is appreciated!

private void button2_Click(object sender, EventArgs e)
{
    AddNewCourse ANCform = new AddNewCourse();
    ANCform.FormClosing += new FormClosingEventHandler(this.ANC_FormClosing);
    ANCform.Show();
}
private void ANC_FormClosing(object sender, FormClosingEventArgs e)
{
    this.Refresh();
}

Solution

  • Rebind the datasource of your DataGridView in ANC_FormClosing

    For example, if I were rebinding using a method that fetches data, I might write

    private void ANC_FormClosing(object sender, FormClosingEventArgs e)
    {
        DataGridView.DataSource = GetFromDB();
    }
    

    This refreshes the grid with new data fresh from the DB