What is the best way to inform a second form that it's data has been changed

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

I have two forms each containing a DataGridView that has a textFile as it's
data.
When I want to save the DataGridView to the textfile I push the save button.

If I for example change the DataGridView in one of the form and then push
the save button
how do I best inform the other form that it has to reload the DataGridView
because the data(textfile)
has been changed.

Somebody might have a simple example for this kind of thing.


//Tony
 
Tony,

The DataTable has strange enough no method "haschanges",

However you know if the method

DataRow[] drs = DataTable.GetChanges();
returns null then it has no changes.

Cor
 
Hello!

I mean to inform the other form that it has to relead the DataGridView from
the textfile is the best way here to use delegate.

//Tony


Cor Ligthert said:
Tony,

The DataTable has strange enough no method "haschanges",

However you know if the method

DataRow[] drs = DataTable.GetChanges();
returns null then it has no changes.

Cor

Tony Johansson said:
Hello!

I have two forms each containing a DataGridView that has a textFile as
it's data.
When I want to save the DataGridView to the textfile I push the save
button.

If I for example change the DataGridView in one of the form and then push
the save button
how do I best inform the other form that it has to reload the
DataGridView because the data(textfile)
has been changed.

Somebody might have a simple example for this kind of thing.


//Tony
 
Tony Johansson said:
I mean to inform the other form that it has to relead the DataGridView
from the textfile is the best way here to use delegate.

I'd suggest using an event. On the form that must inform the other one
that the data has changed, expose a public event and raise it when changing
the data. The form that needs the notification can suscribe to the event and
reload the data in the event handler routine.
 
Hello!

But if I will use an event I must create a delegate because the type of the
event is the definition of the delegate.

//Tony
 
Tony Johansson said:
Hello!

I have two forms each containing a DataGridView that has a textFile as
it's data.
When I want to save the DataGridView to the textfile I push the save
button.

If I for example change the DataGridView in one of the form and then push
the save button
how do I best inform the other form that it has to reload the DataGridView
because the data(textfile)
has been changed.

If you want to reload when the textfile changes, then you'll need
FileSystemWatcher. Textfiles can be changed by any program, not just yours.
 
Tony Johansson said:
Hello!

I mean to inform the other form that it has to relead the DataGridView
from the textfile is the best way here to use delegate.

//Tony
Here is an idea. How about a global flag. Once you change the data, you
set the flag to TRUE. In your second form, just read the flag. Simple.
Works.
 
Hello!

Ben's suggestion will hold perfectly

//Tony

Peter Duniho said:
[...]
If I for example change the DataGridView in one of the form and then
push the save button
how do I best inform the other form that it has to reload the
DataGridView because the data(textfile)
has been changed.

If you want to reload when the textfile changes, then you'll need
FileSystemWatcher. Textfiles can be changed by any program, not just
yours.

Or as an alternative viewpoint: if you are using a text file to
communicate between two forms, and expect for that text file to be changed
by anything else, there is probably a problem with that particular design.

In other words, if you feel that Ben's advice isn't useful, there's
probably something wrong with the approach at a more fundamental level.

Pete
 
Back
Top