Click here to Skip to main content
14,865,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I make a database program where i can add new patients to an access table.
In form1 i click button "add patient".

form 2 opens with textboxes to fill in data.
the data saves correctly but i want to update the patient datagridview on form 1 when i close form2?

What I have tried:

I found a sub that handles me.closed but i can't add form1 to the code?

Private Sub FormMakeDossier_Closed(sender As Object, e As EventArgs) Handles Me.Closed

    End Sub
Updated 7-Nov-20 20:22pm

Use a "static" Observable Collection (OC). The form adds to the collection; the grid gets updated automatically using the OC as its data source; and the events fired when the collection changes can be used to update the Access db.
Handle the Closed event in Form1 by adding it to the Form2 instance you create just before you call Show on it.
When the Form2instance closes, the event will be raised, and you will have Form1 in Me as usual, and Form2 is passed to you as the sender parameter.
You can then use a property or method in Form2 to access the information Form1 needs:

The form that creates an instance of another:
MyForm mf = new MyForm();
Is the "parent", the other form is the "child".
(This doesn't imply any formal MDI relationship)

Transferring information between two forms, Part 2: Child to Parent[^] The code is in C#, but it's pretty simple and obvious.
Izzy Decorte 11-Nov-20 8:59am
I'm sorry, I can't get it to work. I'm not versed in c# , nor converting this to
OriginalGriff 11-Nov-20 9:23am
It's pretty trivial: create an event in your Form2 (
Handle it in Form1 (you know how to do that already)
Raise it from Form2 when you want Form1 to start the timer. (see link above)
In the handler, start your timer.

Give it a try!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900