Thomas

Thomas

  • NA
  • 111
  • 0

returning array from modal form

Mar 27 2012 2:07 PM
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?

Answers (8)