Solved

Refresh Data on Form A while working in Form B

Posted on 2006-06-28
7
303 Views
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?

Thanks
0
Comment
Question by:danorme
  • 4
  • 3
7 Comments
 
LVL 34

Expert Comment

by:Sancler
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?

Roger
0
 

Author Comment

by:danorme
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?
0
 
LVL 34

Expert Comment

by:Sancler
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 ;-)

Roger
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 34

Expert Comment

by:Sancler
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 ;-)

Roger
0
 

Author Comment

by:danorme
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
DataSetA.Clear
sqlDataAdapater.Fill(DataSetA.MyTable)
End If

Would something like this work?

Good night?
0
 
LVL 34

Accepted Solution

by:
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.

Roger
0
 

Author Comment

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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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