Solved

Refresh Data on Form A while working in Form B

Posted on 2006-06-28
7
284 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now