Moving Data from one form to another
-
I'm trying to take data collected on a form, and output it to another form, but I'm getting an "inaccessible due to its protection level" error. So I have form A, that has a panel with some dynamically generated textboxes. FormA -> panelA -> txtQtyA In Form B, I want to access the data, and I'm trying to use: txtQtyB.text = FromA.panelA.txtQtyA.Text, but I get the error for panelA. I have tried changing the forms constructor to Public, just to see if it would "see" it with no luck. Any assistance would be appreciated.
-
I'm trying to take data collected on a form, and output it to another form, but I'm getting an "inaccessible due to its protection level" error. So I have form A, that has a panel with some dynamically generated textboxes. FormA -> panelA -> txtQtyA In Form B, I want to access the data, and I'm trying to use: txtQtyB.text = FromA.panelA.txtQtyA.Text, but I get the error for panelA. I have tried changing the forms constructor to Public, just to see if it would "see" it with no luck. Any assistance would be appreciated.
You need to edit this: "FromA.panelA.txtQtyA" in the Visual Designer. It's got a property called "Modifiers" which is set to Private. You'll want to make that either Internal or Public - depending on your needs. Best, John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
-
You need to edit this: "FromA.panelA.txtQtyA" in the Visual Designer. It's got a property called "Modifiers" which is set to Private. You'll want to make that either Internal or Public - depending on your needs. Best, John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
That removed the error, but introduced another. I now get an error on the same line but is is under FormA.PanelA stating: An object reference is required for the non-static field, method or property. txtQtyB.Text = FormA.panelA.txtQtyA.Text; I'm not sure how I can change the accessor for a dynamically created control? And just to add a little more. FormA creates and calls FormB.
-
That removed the error, but introduced another. I now get an error on the same line but is is under FormA.PanelA stating: An object reference is required for the non-static field, method or property. txtQtyB.Text = FormA.panelA.txtQtyA.Text; I'm not sure how I can change the accessor for a dynamically created control? And just to add a little more. FormA creates and calls FormB.
You need an instance of FormA, like:
var forma = new FormA();
txtQtyB.Text = forma.panelA.txtQtaA.Text;Or, more likely:
var forma = new FormA();
txtQtyB.Text = forma.txtQtaA.Text;-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
-
I'm trying to take data collected on a form, and output it to another form, but I'm getting an "inaccessible due to its protection level" error. So I have form A, that has a panel with some dynamically generated textboxes. FormA -> panelA -> txtQtyA In Form B, I want to access the data, and I'm trying to use: txtQtyB.text = FromA.panelA.txtQtyA.Text, but I get the error for panelA. I have tried changing the forms constructor to Public, just to see if it would "see" it with no luck. Any assistance would be appreciated.
Changing the 'Ctor of a Form's access to 'Public is a mistake. You need to set up a dynamic linkage between the run-time created TextBoxes in FormA and FormB. There are several ways you could do this, all relatively simple to implement. One example: 1. if FormB is a "Main Form" and creates the instance of FormA, you could have code in FormB create the TextBoxes at run-time and inject them into FormA: that way, FormB would have direct references to the TextBoxes. To select from several other possible techniques, it would be helpful to know: 1. which is the "Main Form" here: A, B, or ? if A is not the Main Form where is the code that declares an instance of it and shows it ? 2. which is the Form in which the run-time TextBoxes in A are created: A ? or ? 3. do the number of TextBoxes created at run-time vary, or are they always the same number of TextBoxes ?
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
-
You need to edit this: "FromA.panelA.txtQtyA" in the Visual Designer. It's got a property called "Modifiers" which is set to Private. You'll want to make that either Internal or Public - depending on your needs. Best, John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
No. This is a bad idea - it ties the two design of the two forms together and means they can't be modified without considering the impact of changes on the outside world. The default setting is private for a reason, and changing it to public is a hack!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
I'm trying to take data collected on a form, and output it to another form, but I'm getting an "inaccessible due to its protection level" error. So I have form A, that has a panel with some dynamically generated textboxes. FormA -> panelA -> txtQtyA In Form B, I want to access the data, and I'm trying to use: txtQtyB.text = FromA.panelA.txtQtyA.Text, but I get the error for panelA. I have tried changing the forms constructor to Public, just to see if it would "see" it with no luck. Any assistance would be appreciated.
Bill is absolutely right - making the controls public is a bad mistake. This is a simple thing to do, and it's not difficult to manage correctly. Exactly how you do it depends on the "relationship" between the two forms, but one of these will cover it: Transferring information between two forms, Part 1: Parent to Child[^] Transferring information between two forms, Part 2: Child to Parent[^] Transferring information between two forms, Part 3: Child to Child[^] In all three, the "Parent" is the form that creates an instance of the "Child" via the
new
keyword.Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
You need an instance of FormA, like:
var forma = new FormA();
txtQtyB.Text = forma.panelA.txtQtaA.Text;Or, more likely:
var forma = new FormA();
txtQtyB.Text = forma.txtQtaA.Text;-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!
Or even more likely, he needs the existing instance of the form that the user entered data into... :sigh:
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...