Solved

Refresh Data on Form A while working in Form B

Posted on 2006-06-28
7
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

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 (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

739 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