passing values between forms (winforms)

Posted by dnkira on Stack Overflow See other posts from Stack Overflow or by dnkira
Published on 2010-06-17T14:31:33Z Indexed on 2010/06/17 15:33 UTC
Read the original article Hit count: 337

Filed under:
|
|

Hello. Vierd behaviar when passing values to and from 2nd form.

ParameterForm pf = new ParameterForm(testString);

works

ParameterForm pf = new ParameterForm();
pf.testString="test";

doesn't (testString defined as public string)

maybe i'm missing something? anyway i'd like to make 2nd variant work properly, as for now - it returns null object reference error.

thanks for help.

posting more code here:

calling

Button ParametersButton = new Button();
ParametersButton.Click += delegate
                {
                    ParameterForm pf = new ParameterForm(doc.GetElementById(ParametersButton.Tag.ToString()));
                    pf.ShowDialog(this);
                    pf.test = "test";
                    pf.Submit += new ParameterForm.ParameterSubmitResult(pf_Submit);
                };

definition and use

   public partial class ParameterForm : Form
    {
        public string test;
        public XmlElement node;
        public delegate void ParameterSubmitResult(object sender, XmlElement e);
        public event ParameterSubmitResult Submit;

        public void SubmitButton_Click(object sender, EventArgs e)
        {
            Submit(this,this.node);
            Debug.WriteLine(test);
        }
     }

result: Submit - null object reference test - null object reference

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms