Accessing Form Data from another form
-
I have a main dialog. I then create many new dialog forms which the user interacts with to enter values. I want to be able to retrieve the values that the user enters. I am wondering the best way to design my system to allow access to the values entered by the user in the dialog forms. In my main form, I could add a public access to the dialog form instance. This seems inefficiant and seems to need a lot of effort to maintian. Or perhaps I could update some central class with the entered values. Then I would access that class to retrieve the values. I am sure this is a common thing that has to be done. Does anyone have suggestion as to the best way to achieve this? Thanks, Liam
-
I have a main dialog. I then create many new dialog forms which the user interacts with to enter values. I want to be able to retrieve the values that the user enters. I am wondering the best way to design my system to allow access to the values entered by the user in the dialog forms. In my main form, I could add a public access to the dialog form instance. This seems inefficiant and seems to need a lot of effort to maintian. Or perhaps I could update some central class with the entered values. Then I would access that class to retrieve the values. I am sure this is a common thing that has to be done. Does anyone have suggestion as to the best way to achieve this? Thanks, Liam
There are loads of ways of doing this, here are 2 The simplest and worst of them is to change your controls to be public (I think this works, but would not recommend it) Expose some public properties on your form to read the variables. eg. public string MyTextBoxValue { get { return TextBox1.Text; } } you can also do clever things with a static factory method on the form which takes parameters as refs HTH Russ