Refresh a form 
Author Message
 Refresh a form

Hi

I'm working on a fairly simple app comprising of 4 forms.

On the 1st form it shows some stats from 2 txt file it links too (how many
lines etc).

On Form 2 it allows you to add info to one of the txt files.

I open Form 2 when wanting to add another record using Form2.ShowDialog()
When I've added the link and clicked save I close form2 with Close().  The
the focus is back on form 1

Is there anything I can do to automatically refresh form1 so that the stats
update once I close form 2?

Thanks
Gerry



Sun, 30 Oct 2011 20:42:23 GMT  
 Refresh a form


Quote:
> Hi

> I'm working on a fairly simple app comprising of 4 forms.

> On the 1st form it shows some stats from 2 txt file it links too (how many
> lines etc).

> On Form 2 it allows you to add info to one of the txt files.

> I open Form 2 when wanting to add another record using Form2.ShowDialog()
> When I've added the link and clicked save I close form2 with Close().  The
> the focus is back on form 1

> Is there anything I can do to automatically refresh form1 so that the
stats
> update once I close form 2?

[Hope I got the direction right... <g>]

In Form2 provide a Event to send back the information

In Form1 declare your Form2 reference using
     Private WithEvents frmTwo As Form2
Add the Event to Form1
In Form2 when ever you want to update Form1 raise the event

-ralph



Sun, 30 Oct 2011 20:56:48 GMT  
 Refresh a form
Here are two other ways to implement communication:

In Form1 create one or more properties for the information you would like
updated.
In Form2 create a reference to Form1, and then when you want to update Form1
simply call that property.

or...

If there is a specific control on Form1 you would like updated, then create
a reference to that control in Form1.
Set the reference before calling Form2.
Then in Form2 chew on Form1's control.

You can also chew on specific controls in Form1 from Form2 vie a Form1
reference (using the controls collection,etc).

This latter scheme, while efficient is generally frowned upon as it is a
flagrant violation of encapsulation and more tightly binds the two forms.

-ralph



Sun, 30 Oct 2011 21:14:32 GMT  
 Refresh a form


Quote:
> Here are two other ways to implement communication:

> In Form1 create one or more properties for the information you would
> like updated.
> In Form2 create a reference to Form1, and then when you want to update
> Form1 simply call that property.

> or...

> If there is a specific control on Form1 you would like updated, then
> create a reference to that control in Form1.
> Set the reference before calling Form2.
> Then in Form2 chew on Form1's control.

> You can also chew on specific controls in Form1 from Form2 vie a Form1
> reference (using the controls collection,etc).

> This latter scheme, while efficient is generally frowned upon as it is
> a flagrant violation of encapsulation and more tightly binds the two
> forms.

> -ralph

Or......in Form1, can't you declare the Sub that refreshes the Form1 data
as Public, and then in the Form2 unload event, just call Form1.sub ?


Sun, 30 Oct 2011 22:20:20 GMT  
 Refresh a form


Quote:
> Hi

> I'm working on a fairly simple app comprising of 4 forms.

> On the 1st form it shows some stats from 2 txt file it links too (how many
> lines etc).

> On Form 2 it allows you to add info to one of the txt files.

> I open Form 2 when wanting to add another record using Form2.ShowDialog()
> When I've added the link and clicked save I close form2 with Close().  The
> the focus is back on form 1

> Is there anything I can do to automatically refresh form1 so that the
stats
> update once I close form 2?

Dang!

I completely skipped right over ".ShowDialog()".

You're using VB.Net, correct?

While my suggestions will work in the general, for specific code you need to
post to a dotNet group. Perhaps
    microsoft.public.dotnet.languages.vb

-ralph



Sun, 30 Oct 2011 22:20:00 GMT  
 Refresh a form


Quote:


> > Here are two other ways to implement communication:

> > In Form1 create one or more properties for the information you would
> > like updated.
> > In Form2 create a reference to Form1, and then when you want to update
> > Form1 simply call that property.

> > or...

> > If there is a specific control on Form1 you would like updated, then
> > create a reference to that control in Form1.
> > Set the reference before calling Form2.
> > Then in Form2 chew on Form1's control.

> > You can also chew on specific controls in Form1 from Form2 vie a Form1
> > reference (using the controls collection,etc).

> > This latter scheme, while efficient is generally frowned upon as it is
> > a flagrant violation of encapsulation and more tightly binds the two
> > forms.

> > -ralph

> Or......in Form1, can't you declare the Sub that refreshes the Form1 data
> as Public, and then in the Form2 unload event, just call Form1.sub ?

Yes. Which is more or less what I assumed would be performed by setting a
Property. ie, the Property would manage what ever updating needed to be
done.

If you already have a Sub that does the updating then making it Public would
be a simple fix.

Publishing an Interface with Methods and/or Properties is fine. But my
comfort level goes down with your comment "... *the* Sub that refreshes the
Form1 data ...". (The emphasis is mine.)

If this Sub is used within the context of performing Form1 tasks it places
the extra burden on the developer (and latter maintainers) to be aware *the*
Sub might be called "out of context". I like to keep the two separated. But
that's drawing a fine line and certainly nothing to go to the mat over. :-)

-ralph



Sun, 30 Oct 2011 23:11:12 GMT  
 Refresh a form

Quote:





> > > Here are two other ways to implement communication:

> > > In Form1 create one or more properties for the information you would
> > > like updated.
> > > In Form2 create a reference to Form1, and then when you want to update
> > > Form1 simply call that property.

> > > or...

> > > If there is a specific control on Form1 you would like updated, then
> > > create a reference to that control in Form1.
> > > Set the reference before calling Form2.
> > > Then in Form2 chew on Form1's control.

> > > You can also chew on specific controls in Form1 from Form2 vie a Form1
> > > reference (using the controls collection,etc).

> > > This latter scheme, while efficient is generally frowned upon as it is
> > > a flagrant violation of encapsulation and more tightly binds the two
> > > forms.

> > > -ralph

> > Or......in Form1, can't you declare the Sub that refreshes the Form1 data
> > as Public, and then in the Form2 unload event, just call Form1.sub ?

> Yes. Which is more or less what I assumed would be performed by setting a
> Property. ie, the Property would manage what ever updating needed to be
> done.

> If you already have a Sub that does the updating then making it Public would
> be a simple fix.

> Publishing an Interface with Methods and/or Properties is fine. But my
> comfort level goes down with your comment "... *the* Sub that refreshes the
> Form1 data ...". (The emphasis is mine.)

> If this Sub is used within the context of performing Form1 tasks it places
> the extra burden on the developer (and latter maintainers) to be aware *the*
> Sub might be called "out of context". I like to keep the two separated. But
> that's drawing a fine line and certainly nothing to go to the mat over. :-)

> -ralph

And if the data shown in form1 refresh changes they need to know this
for the form2 routine. I would put the sub in a module and have one
place to maintain the code.


Mon, 31 Oct 2011 00:23:46 GMT  
 Refresh a form
Sorry, my mistake, posted in the wrong group!

Thanks.

Gerry


Quote:



>> Hi

>> I'm working on a fairly simple app comprising of 4 forms.

>> On the 1st form it shows some stats from 2 txt file it links too (how
>> many
>> lines etc).

>> On Form 2 it allows you to add info to one of the txt files.

>> I open Form 2 when wanting to add another record using Form2.ShowDialog()
>> When I've added the link and clicked save I close form2 with Close().
>> The
>> the focus is back on form 1

>> Is there anything I can do to automatically refresh form1 so that the
> stats
>> update once I close form 2?

> Dang!

> I completely skipped right over ".ShowDialog()".

> You're using VB.Net, correct?

> While my suggestions will work in the general, for specific code you need
> to
> post to a dotNet group. Perhaps
>    microsoft.public.dotnet.languages.vb

> -ralph



Mon, 31 Oct 2011 00:07:41 GMT  
 Refresh a form
Since you didn't re-post, you may not have noticed that you didn't get the
full range of options.

If you build that second form using the Dialog template (instead of a
standard form) then you can get a return value from .ShowDialog that
indicates the dialog result. Use that value to determine how the form needs
to be updated.


Quote:
> Sorry, my mistake, posted in the wrong group!

> Thanks.

> Gerry



Tue, 01 Nov 2011 07:13:05 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Refreshing a form

2. Screen refreshing on form with embedded Excel chart

3. Auto-refresh a form

4. Refreshing parent form

5. Repost: Datagrid refresh brings form to front

6. Datagrid refresh brings form to front

7. Refreshing a form?

8. Refreshing a form...

9. disable F5 (refresh) after form posting

10. Refreshing a Form Page

11. Reports not refreshing in form?

12. Stored procedure (Refresh the form??) DRIVING ME CRAZY

 

 
Powered by phpBB® Forum Software