Bidirectional form communication

  • Thread starter The Dubious Khelair
  • Start date
T

The Dubious Khelair

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I must've read over 20 threads so far that I've googled about accessing
form elements from another form in the quest to answer this issue, and
the most common reply that I came across is 'JFGIY' (Just Effing Google
It Yourself). So in my defense I would like to say that I've tried
googling this a half a dozen ways and I can't really think of any other
way to put it that might turn up better hits. I digress; here is my
problem.

I've got an application that I'm building whose parent form has a List
of custom classes that I need to try to access from the child form. At
the same time, I need to be able to access CheckListBox elements from
the parent form, and I need to be able to pass back from child to parent
some modified versions of all of the above. It's basically a form that
opens for editing some of the details on the primary form, where it is
not aesthetically correct to have the editing options available.

Most of the detailed discussions I've come across mention that you have
to designate a variable (I hope that's the right word in this case) as
the name/type form that you have created for each one and then you can
access its members via the dot operator as per standard OOP.
Unfortunately I find that when I have each form with a section in their
respective code declaring a variable to be equal to a new form of the
other form's type that this causes a StackOverflowException or something
of the like.

For now I've made the editing options on my application unavailable;
obviously this is not the solution that I am looking for. Can anybody
help my poor quality of google-fu and point me in the direction of a
resource that will handle this case, and/or help me to understand a
solution to this situation a little bit better?

Thank you in advance, I appreciate any pointers you may be able to
offer.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (OpenBSD)

iQIcBAEBAgAGBQJP+Q6TAAoJECqJ6HQbyBt4LW8P/Agnqca2X5OeKvxv9oClQl2l
8RerykvYI0xi2Jb0BS7gXcitbRFXBLlZzWdmM7wMDQlODC1EqqtPwYI24F/CvN2m
Y1Fwu5BSZ2lI8+uc+Yn3Om56KTHRkIbl88nIkcosUzHCo8yibc1fS8VXJISWUL62
mfVwtCPoxcSSwW8fsLuL3TWebxVrD98T8Fg3OKzhUbB/8CuTVqfv30GiW3w1cSA9
Oo7cimh1Pl7c8TmnwmEO4dikLU8qxR6iztSTYQhYbHU1+PxLvQr1hZgAvBn76DSm
kNsSq8Ystpu6tCg2MtlQyOqByIKnsEkL0OJPAALg6isM9t01N0tdDkNu5lhGROxr
mi5kMn8zrzw9dfPoq/4e8Sp8li9U4aeFlD/5De7nng+MjAUjhVzE5pxkwIU+jADO
IULikgwZ+yrYVF4d9OTYNoAFic1hzO5br+fBw6/086kLqSiVDB7TOm9FRalqSBI2
FHbXqxNqp6V5hWyUbMvHCiP3FweSxq9lPxqvW67VQ8bS1RjS9gEnDc44G/TOov/i
A2waKRnEH0krQGX5uheNC6KuX7D7u0aK9vQcoX5qDtKq+78BSqYa+1+8tZxtKpOu
6aFrZsWzQPWM2WAGQMyvKtTe+cWjxXTyfyvsy2TYuNypE0oRiB2/xeaQk//1XsxV
fV4f/3jKHHMc4pDqByeT
=0DeB
-----END PGP SIGNATURE-----
 
B

bradbury9

El domingo, 8 de julio de 2012 06:50:12 UTC+2, The Dubious Khelair escribió:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I must've read over 20 threads so far that I've googled about accessing
form elements from another form in the quest to answer this issue, and
the most common reply that I came across is 'JFGIY' (Just Effing Google
It Yourself). So in my defense I would like to say that I've tried
googling this a half a dozen ways and I can't really think of any other
way to put it that might turn up better hits. I digress; here is my
problem.

I've got an application that I'm building whose parent form has a List
of custom classes that I need to try to access from the child form. At
the same time, I need to be able to access CheckListBox elements from
the parent form, and I need to be able to pass back from child to parent
some modified versions of all of the above. It's basically a form that
opens for editing some of the details on the primary form, where it is
not aesthetically correct to have the editing options available.

Most of the detailed discussions I've come across mention that you have
to designate a variable (I hope that's the right word in this case) as
the name/type form that you have created for each one and then you can
access its members via the dot operator as per standard OOP.
Unfortunately I find that when I have each form with a section in their
respective code declaring a variable to be equal to a new form of the
other form's type that this causes a StackOverflowException or something
of the like.

For now I've made the editing options on my application unavailable;
obviously this is not the solution that I am looking for. Can anybody
help my poor quality of google-fu and point me in the direction of a
resource that will handle this case, and/or help me to understand a
solution to this situation a little bit better?

Thank you in advance, I appreciate any pointers you may be able to
offer.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (OpenBSD)

iQIcBAEBAgAGBQJP+Q6TAAoJECqJ6HQbyBt4LW8P/Agnqca2X5OeKvxv9oClQl2l
8RerykvYI0xi2Jb0BS7gXcitbRFXBLlZzWdmM7wMDQlODC1EqqtPwYI24F/CvN2m
Y1Fwu5BSZ2lI8+uc+Yn3Om56KTHRkIbl88nIkcosUzHCo8yibc1fS8VXJISWUL62
mfVwtCPoxcSSwW8fsLuL3TWebxVrD98T8Fg3OKzhUbB/8CuTVqfv30GiW3w1cSA9
Oo7cimh1Pl7c8TmnwmEO4dikLU8qxR6iztSTYQhYbHU1+PxLvQr1hZgAvBn76DSm
kNsSq8Ystpu6tCg2MtlQyOqByIKnsEkL0OJPAALg6isM9t01N0tdDkNu5lhGROxr
mi5kMn8zrzw9dfPoq/4e8Sp8li9U4aeFlD/5De7nng+MjAUjhVzE5pxkwIU+jADO
IULikgwZ+yrYVF4d9OTYNoAFic1hzO5br+fBw6/086kLqSiVDB7TOm9FRalqSBI2
FHbXqxNqp6V5hWyUbMvHCiP3FweSxq9lPxqvW67VQ8bS1RjS9gEnDc44G/TOov/i
A2waKRnEH0krQGX5uheNC6KuX7D7u0aK9vQcoX5qDtKq+78BSqYa+1+8tZxtKpOu
6aFrZsWzQPWM2WAGQMyvKtTe+cWjxXTyfyvsy2TYuNypE0oRiB2/xeaQk//1XsxV
fV4f/3jKHHMc4pDqByeT
=0DeB
-----END PGP SIGNATURE-----

Not sure about the problem you are having. You can always write a property in the child form to access the parent. Just have to remember the scope of the variables.

ParentForm.cs

// Calling from the parent form.

ChildForm frm;

// pivate void showChildButton(){
ChildForm frm = new ChilfForm();
// subscribe to child form events if necessary. You can have fun with delegates and eventhandlers
frm.CallingForm = this;
frm.ShowDialog();
frm.Dispose();
frm = null;
}


//Accesing child form, check if it is null (not null == Shown)

private void accessChild(){
if(child!= null) child.publicIntProperty += 1;
}


ChildForm.cs

// declaring property
public ParentForm CallingForm {get; set;}

// sending data back to parent form

private void buttonSendData(){
this.CallingForm.variable = XXXX;
this.CallingForm.method();
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top