I have two forms. The first form has a datagrid. The second form is opened
by the first form. When the second form closes, I want the datagrid on the
first form to refresh.

I tried using the Activated and Enter events of the first form, but neither
fires when the second form closes even though it's the first form that is
then given the focus. I don't see a "Got Focus" or similar event.

Suggestions? Thanks in advance.

Mark

Re: Form activated by Ajay

Ajay
Sat Dec 04 21:11:01 CST 2004

Handle form_Closing event in second form. You can pass the first form to
second form in its constructor.

--
Ajay Kalra [MVP - VC++]
ajaykalra@yahoo.com


"Mark" <field027@idonotlikejunkmail.umn.edu> wrote in message
news:eswOm$k2EHA.3616@TK2MSFTNGP11.phx.gbl...
> I have two forms. The first form has a datagrid. The second form is
opened
> by the first form. When the second form closes, I want the datagrid on
the
> first form to refresh.
>
> I tried using the Activated and Enter events of the first form, but
neither
> fires when the second form closes even though it's the first form that is
> then given the focus. I don't see a "Got Focus" or similar event.
>
> Suggestions? Thanks in advance.
>
> Mark
>
>



Re: Form activated by Dave

Dave
Mon Dec 06 11:57:57 CST 2004

Pardon me for butting in, but how would you do this?


If Form1 has the following code to launch Form2:

private void button1_Click(object sender, System.EventArgs e)
{
Form2 myForm2 = new Form2();
myForm2.Show();
this.Hide();
}


Then on Form2 when I want to redisplay Form1, how do I "pass the first form
to second form in its constructor."

If I do this on Form2:

private void Form2_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
Form1 myForm1 = new Form1();
myForm1.Show();
}

Then a Form1 will display when Form2 closes but it will be a new Form1. The
original Form1 remains hidden so now I have two Form1's in memory.

Is this the proper way to handle this?

Dave


"Ajay Kalra" <ajaykalra@yahoo.com> wrote in message
news:O66KfXn2EHA.3504@TK2MSFTNGP12.phx.gbl...
> Handle form_Closing event in second form. You can pass the first form to
> second form in its constructor.
>
> --
> Ajay Kalra [MVP - VC++]
> ajaykalra@yahoo.com
>
>
> "Mark" <field027@idonotlikejunkmail.umn.edu> wrote in message
> news:eswOm$k2EHA.3616@TK2MSFTNGP11.phx.gbl...
> > I have two forms. The first form has a datagrid. The second form is
> opened
> > by the first form. When the second form closes, I want the datagrid on
> the
> > first form to refresh.
> >
> > I tried using the Activated and Enter events of the first form, but
> neither
> > fires when the second form closes even though it's the first form that
is
> > then given the focus. I don't see a "Got Focus" or similar event.
> >
> > Suggestions? Thanks in advance.
> >
> > Mark
> >
> >
>
>



Re: Form activated by Mark

Mark
Mon Dec 06 13:21:49 CST 2004

feel free to butt away ...

Ajay's suggestions worked just fine, although i still don't get why my
original Activated and Enter events didn't do the job.

I'm winging this in pseudo code, but in form2, you'd need to change it to be
something like ...


public class Form2
{

private Form1 _frm;

public Form2(Form1 frm)
{
_frm = frm; //Sets a reference to the form1 instance;
}

public void CloseSomethingOrOtherEvent()
{
//Note that this does NOT create a new instance of the form, but uses
the existing reference held in _frm.
_frm.SomePublicMethodOnForm1ThatRefreshesDataGrid();
}

}

***** AND THEN *****

1. In form1 you'd do something like:

> Form2 myForm2 = new Form2( this );
> myForm2.Show();



HTH.

Mark
www.dovetaildatabases.com



"Dave" <dave@nospam.ru> wrote in message
news:uy$di072EHA.1188@tk2msftngp13.phx.gbl...
> Pardon me for butting in, but how would you do this?
>
>
> If Form1 has the following code to launch Form2:
>
> private void button1_Click(object sender, System.EventArgs e)
> {
> Form2 myForm2 = new Form2();
> myForm2.Show();
> this.Hide();
> }
>
>
> Then on Form2 when I want to redisplay Form1, how do I "pass the first
form
> to second form in its constructor."
>
> If I do this on Form2:
>
> private void Form2_Closing(object sender,
> System.ComponentModel.CancelEventArgs e)
> {
> Form1 myForm1 = new Form1();
> myForm1.Show();
> }
>
> Then a Form1 will display when Form2 closes but it will be a new Form1.
The
> original Form1 remains hidden so now I have two Form1's in memory.
>
> Is this the proper way to handle this?
>
> Dave
>
>
> "Ajay Kalra" <ajaykalra@yahoo.com> wrote in message
> news:O66KfXn2EHA.3504@TK2MSFTNGP12.phx.gbl...
> > Handle form_Closing event in second form. You can pass the first form to
> > second form in its constructor.
> >
> > --
> > Ajay Kalra [MVP - VC++]
> > ajaykalra@yahoo.com
> >
> >
> > "Mark" <field027@idonotlikejunkmail.umn.edu> wrote in message
> > news:eswOm$k2EHA.3616@TK2MSFTNGP11.phx.gbl...
> > > I have two forms. The first form has a datagrid. The second form is
> > opened
> > > by the first form. When the second form closes, I want the datagrid
on
> > the
> > > first form to refresh.
> > >
> > > I tried using the Activated and Enter events of the first form, but
> > neither
> > > fires when the second form closes even though it's the first form that
> is
> > > then given the focus. I don't see a "Got Focus" or similar event.
> > >
> > > Suggestions? Thanks in advance.
> > >
> > > Mark
> > >
> > >
> >
> >
>
>



Re: Form activated by Bjarke

Bjarke
Tue Dec 14 06:06:11 CST 2004

Mark wrote:

> feel free to butt away ...

Thanks ;)

> public Form2(Form1 frm)
> {
> _frm = frm; //Sets a reference to the form1 instance;
> }

Well - this way Form2 is dependant on Form1.

Wouldn't it be 'cleaner' if you let Form1 handle the Form2's
CloseSomethingOrOtherEvent?


> 1. In form1 you'd do something like:
>
> > Form2 myForm2 = new Form2( this );
> > myForm2.Show();

Or:

Form2 myForm2 = new Form2();
myForm2.CloseSomethingOrOtherEvent
+= new EventHandler(this.HandleForm2Close);
myForm2.Show();


/B