I've tried searching and the only thing I can find is passing data to a new instance of a form.
I have an open form that opens a modal form. On that Modal form, a dynamically created a array is build and I need to return that value to the original form that is open.
I've passed data between MDI forms using parent and child but those are null on this modal form. I was able to set the open form to be the Owner of the modal form but that does not appear to give me access to the public variables on that open form.
I've tried ref and out in the constructor but then I get out of scope errors when I try to access that variable outside the constructor.
on form1 (open form) I have a public string array and the following code:
frmAttachments cAttachments = new frmAttachments();
cAttachments.StartPosition = FormStartPosition.CenterParent;
cAttachments.ShowDialog(this);
on form2 (Modal form) I have the following code:
private string[] Attachments = new string[1];
public frmAttachments()
{
InitializeComponent();
}
{
Other buttons and code to build Attachments Array.
}
private void btnDone_Click(object sender, EventArgs e)
{
this.Close();
//At this point I need form1 to have the 'Attachments' string array values.
}
Any suggestions?
Loading
FroglegPosted Mar 27, 2012, 4:10 PM
VulpesPosted Mar 27, 2012, 5:20 PM
So, if that seems simpler to you, I'd go with that.
ThomasPosted Mar 27, 2012, 5:00 PM
However. the delegates approach (modal zip file) was actually much simpler and I suspect more efficient. Once I got that project setup so I could see it in action.
I would be interested to know if there are downsides or things to be aware of with the delegates approach.
ThomasPosted Mar 27, 2012, 4:37 PM
VulpesPosted Mar 27, 2012, 4:37 PM
ThomasPosted Mar 27, 2012, 4:34 PM
ThomasPosted Mar 27, 2012, 4:25 PM
SOOO VERY Close!!! When I run it I get an error because it is the wrong form as the owner.
Form1 is an MDI child and stepping through the code it looks right but when I get to the Modal form the Owner is the MDI Parent form not the Child form that sent it.
cAttachments.ShowDialog(this); // Here in the code stepping though, 'this' appears to point to the proper child form
I threw a messagebox into the form load and at that point the owner is the MDI Parent form. It is trying to cast 'this' as the wrong form and it gives me an error.
VulpesPosted Mar 27, 2012, 3:48 PM