Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refresh DatagridView on Main Form when another form closes

Status
Not open for further replies.

RJL1

Technical User
Oct 3, 2002
228
US
Hello

I am struggling getting my DatagridView refreshed when the confirmation form closes. Here is the layout of my application

Form_Appt_Main - this has the datagrid which on load populates with all the appointments schedules. I have a button btnNew which opens Form_Appt_New

Form_Appt_New - This is where the user enters all required information to book a new appointment. This form has a button btnSave which passed all the information to a class called Class_Appt_New

Class_Appt_New - this validates the data and inserts the new record into the SQL database. When complete if opens a confirmation form Form_Appt_Confirmation. This form has a button btnOK (and other functionality)

Here is my problem when I click the button in the Form_Appt_Confirmation I want it to close the form (done) and refresh the Form_Appt_Main datagrid.

Anu guidance on this would be extremely appreciated
Thanks
RJL
 
If each of the forms from Appt_New onwards are dialogs, then ultimately as they are closed you will return to the main form where you can update the grid from the db.
 
You should have something like (typed, not tested):

On Form_Appt_Main:
Code:
btnNew_OnClick()
{
    var fan = New Form_Appt_New;
    if (fan.OpenDialog() == DialogResult.Ok)
    {
        Datagrid.Refresh()  //Whatever you use to load/reload the datagrid goes here
    }
    fan.Close()
}

On Form_Appt_New:
Code:
btnSave_Click()
{
    //Whatever you need to pass the data to the Class_Appt_New and perform the Save action from that class
    DialogResult = DialogResult.Ok;
}

The key here is opening the Form_Appt_New in Dialog mode. This stops all other code on Form_Appt_Main from continuing until the focus is passed back. That is handled by the Form_Appt_New setting the DialogResult value. The code stack returns to the Main form where the refresh is performed and the Dialog Appt form is closed down completely. You can carry the same logic to the Form_Appt_Confirmation as well to keep the stack in line with what you need for processing in specific order.

Robert "Wizard" Johnson III
U.S. Military Vets MC
CSM, CSPO, MCPD, CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
Data Integration Engineer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top