Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Refresh DatagridView on Main Form when another form closes

Refresh DatagridView on Main Form when another form closes

Refresh DatagridView on Main Form when another form closes


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

RE: Refresh DatagridView on Main Form when another form closes

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.

RE: Refresh DatagridView on Main Form when another form closes

You should have something like (typed, not tested):

On Form_Appt_Main:


    var fan = New Form_Appt_New;
    if (fan.OpenDialog() == DialogResult.Ok)
        Datagrid.Refresh()  //Whatever you use to load/reload the datagrid goes here

On Form_Appt_New:


    //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
Data Integration Engineer

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close