Refresh Data on Form A while working in Form B

Posted on 2006-06-28
Last Modified: 2010-04-23
I have a MDI program that has multiple screens.  But what I am most concerned with is form A and Form B inside the MDI Parent.

Form A opens when the MDI program starts and the end user will open Form B and make changes.

How can I get Form A to update its fields / Data with the changes that Form B has made?

Question by:danorme
  • 4
  • 3
LVL 34

Expert Comment

ID: 17005377
If you are accessing the same data from a number of forms the best idea is to hold that data somewhere (a module? a public class?) from which it accessible to all the forms.  Then if form A's controls are bound to a datatable which form B updates the updates are immediately reflected in form A's controls without any further action on your part.  Would that be viable in your setup?


Author Comment

ID: 17005602
It is by all means the best way to do it, but I am too deep into this to make that type of change.  Version 3 of this program, already started, will use this for sure.  Can you assist with band aid, so to speak?
LVL 34

Expert Comment

ID: 17005744
I'm off to bed now - in the UK, where I am, it's just after midnight - and detailed suggestions would depend on details of your set up which I don't know.  But the basic issue is one of communication between form B and form A.  Somehow, form B needs to tell form A "I've made changes, you'd better use your own mechanisms for updating".  That suggests either adding a public Event to form B which fires when it makes changes and which form A or the MDI parent can listen for.  Or using the link from form B to its MDIParent and from that to its MDIChidren to pass a message direct to form A.

I'm not sure if that will be enough for you to sort something out.  But if not, post some details of how you call forms A and B, and whether form B stays open when it has done its update or its closing might provide a sufficient trigger for form A to update, and that sort of thing and I'll check in again in the morning.  If it's not resolved (by you or someone else on here) by then, I'll see what I can do.

G'nite ;-)

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 34

Expert Comment

ID: 17005778
A quick thought.

A public Boolean variable "DataDirty" in the MDIParent.

When B changes the data it sets

     Me.MDIParent.DataDirty = True

When A becomes active again it runs

    If Me.MDIParent.DataDirty Then
          'updating code
   End If

Now I really must go to bed ;-)


Author Comment

ID: 17006418
I think I might try something like this, it is 9:26pm now, in the morning.  The way I set this thing up was when I first began programming so you can guess that it is UGLY!  Now Version 3 will be cleaner and a lot more efficient, but still done by a person that has a year of programming under his belt, although 15 years of networking and server administration.

Here is what I have so far.  Really the MDIParent is just a holder of other forms and that is really it.  Each form acts almost independently of each other, my mistake.  I am using ADO.NET (disconnected) which has been a new thing for me since I am used to using straight SQL statements.
So let me see if I get this right.

I can do something like this.
>>>Form B<<<
If DataSetA.HasChanges Then
Me.MDIParent.DataDirty = True
End If

>>>Form A<<<
If Me.MDIParent.DataDirty = True Then
End If

Would something like this work?

Good night?
LVL 34

Accepted Solution

Sancler earned 500 total points
ID: 17007405
It might.  That's certainly on the lines of my last post.  I note, however, that

1)  the code in Form B does not actually show an .Update being performed on DataSetA.  If that is not done (and assuming that DataSetA in Form B is different from DataSetA in Form A - see next comment) then the database itself will not show the changed data so refilling the dataset in Form A will not show the changes.

2)  the code from both Form A and Form B refer to DataSetA.  These could be different objects - one declared in Form A and Form B - in which case see the comment above.  But if they are one and the same object - declared at Project level - then any change made to it by one form should automatically be reflected in the other form even before any .Update is performed on it.

3)  on this approach - although I didn't specifically say this - you ought on Form A, besides clearing and re-filling its dataset, to re-set the DataDirty flag to False.


Author Comment

ID: 17009570
Ok, I will give this a try today and let ya know.

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Looping through datagridview and dataset ? 6 33 Error 5 38
ModalPopup  question 22 37
How do I copy a form and rename it in VS2015 2 19
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question