PC Review


Reply
Thread Tools Rate Thread

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

 
 
Tony Johansson
Guest
Posts: n/a
 
      5th May 2009
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


 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      5th May 2009
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" <(E-Mail Removed)> wrote in message
news:Z_ULl.8470$(E-Mail Removed)...
> 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
>


 
Reply With Quote
 
Tony Johansson
Guest
Posts: n/a
 
      5th May 2009
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[MVP]" <(E-Mail Removed)> skrev i meddelandet
news:Ott$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:Z_ULl.8470$(E-Mail Removed)...
>> 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
>>

>



 
Reply With Quote
 
Alberto Poblacion
Guest
Posts: n/a
 
      5th May 2009
"Tony Johansson" <(E-Mail Removed)> wrote in message
news:fKVLl.8472$(E-Mail Removed)...
> 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.

 
Reply With Quote
 
Tony Johansson
Guest
Posts: n/a
 
      5th May 2009
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
"Alberto Poblacion" <earthling-(E-Mail Removed)> skrev i
meddelandet news:(E-Mail Removed)...
> "Tony Johansson" <(E-Mail Removed)> wrote in message
> news:fKVLl.8472$(E-Mail Removed)...
>> 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.
>



 
Reply With Quote
 
Ben Voigt [C++ MVP]
Guest
Posts: n/a
 
      5th May 2009


"Tony Johansson" <(E-Mail Removed)> wrote in message
news:Z_ULl.8470$(E-Mail Removed)...
> 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.

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

 
Reply With Quote
 
Bill Yanaire
Guest
Posts: n/a
 
      5th May 2009

"Tony Johansson" <(E-Mail Removed)> wrote in message
news:fKVLl.8472$(E-Mail Removed)...
> 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.



 
Reply With Quote
 
Tony Johansson
Guest
Posts: n/a
 
      6th May 2009
Hello!

Ben's suggestion will hold perfectly

//Tony

"Peter Duniho" <(E-Mail Removed)> skrev i meddelandet
news(E-Mail Removed)...
> On Tue, 05 May 2009 08:45:00 -0700, Ben Voigt [C++ MVP]
> <(E-Mail Removed)> wrote:
>
>> [...]
>>> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
creating a form-need drop down lists and boxes for input of inform IPERRY Microsoft Word Document Management 1 14th Aug 2009 10:23 PM
data changed on form parez Microsoft Dot NET Framework Forms 1 4th Apr 2008 06:55 AM
How to get an object to inform progress via a form's status bar? sherifffruitfly Microsoft C# .NET 5 23rd Oct 2006 01:03 PM
Event to inform of ActiveControl changed? Martin Hart Microsoft Dot NET Framework Forms 0 21st Sep 2006 06:11 PM
How do I get value what data has changed in my form. KRISH Microsoft Access Forms 2 2nd Sep 2004 02:46 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:54 AM.