|
List Info
Thread: C-Sharp (C#) Group: Re: How do I move data from a pop up form back to the main form?
|
|
| C-Sharp (C#) Group: Re: How do I move
data from a pop up form back to the main
form? |

|
2006-02-07 21:58:42 |
|
Here is my code:
public partial class
AddLocation : Form
{
public string[] newLocation = new
string[1];
public AddLocation()
{
InitializeComponent();
}
private void button1_Click(object
sender, EventArgs e)
{
this.Hide();
}
public void label2_Click(object sender,
EventArgs e)
{
}
private void button2_Click(object
sender, EventArgs e)
{
// Add Button
newLocation[0] = textBox1.Text;
Form1.AddLocationArray(newLocation);
textBox1.Text = "";
}
}
}
The line of Form1.AddLocationArray(); is what fails for me. as you can see I put the variable in the public space. This is what I dont understand. When the user clicks button2, I want to add a member to an array in Form1, from the addLocation form. Does that make sense?
On 2/7/06, J.P. Trosclair < jptrosclair gmail.com">jptrosclair gmail.com> wrote:
Setup public members for in the class for the popup form to hold the data after it closes.
> -----Original Message-----
> From: C_Sharp googlegroups.com">C_Sharp googlegroups.com [mailto: C_Sharp googlegroups.com">C_Sharp googlegroups.com] On Behalf > Of praefex > Sent: Tuesday, February 07, 2006 1:18 PM
> To: C-Sharp (C#) > Subject: C-Sharp (C#) Group: How do I move data from a pop up form back to > the main form? > > > This problem is killing me! I have a main application form, where I
> display all sorts of data. If the user wants to add a new "location", > then I pop up a modal dialog. In this dialog they enter the name of the > location. I make this into a > > string[] newLocation[1];
> > newLocation[0] = textBox1.Text; > > variable and then what I want to do is add this array to an ArrayList > that exists on the Parent Form1. > > So I have 2 Forms, "addLocation" and "Form1". For some reason
everytime > I try to use > > Form1.locationList.Add(newLocation); > > from the "addLocation" form, it fails and gives me the error message: > > Error 1 An object reference is required for the nonstatic field,
> method, or property 'OptivaView.Form1.AddLocationArray(string[])' > > I seutp the method AddLocationArray(str array) on Form1 so it would add > the data to the "data holding" array.
> > Anyone shed some light on this for me? > > -- > No virus found in this incoming message. > Checked by AVG Free Edition. > Version: 7.1.375 / Virus Database: 267.15.2/252 - Release Date:
2/6/2006 >
-- No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.1.375 / Virus Database: 267.15.2/252 - Release Date: 2/6/2006
|
| C-Sharp (C#) Group: Re: How do I move
data from a pop up form back to the main
form? |

|
2006-02-08 00:50:17 |
Hey buddy,
I would strongly suggest you go back to the drawing
board. I can
hint that one of the many problems with the code above is
not
instantiating the form. I understand what you are trying to
do as a
plan, but I do not understand your code. My girlfriend
writes better
code to tell you the truth. Stick to one form calculators
for a little
bit longer! And please don't get offended but right now you
are asking
how to create a nuclear reaction on your first physics class
in high
school!
Marty
|
|
| C-Sharp (C#) Group: Re: How do I move
data from a pop up form back to the main
form? |

|
2006-02-08 02:55:17 |
|
LOL! Thanks! You make a good point, I thrust myself into a project that I had no idea how to do. But I'm learning slowly....Nuclear reactor should be online soon! 
On 2/7/06, Martin Hristoforov (http://www.WhyWeDoIt.com) < mhrist gmail.com">mhrist gmail.com> wrote:
Hey buddy, I would strongly suggest you go back to the drawing board. I can hint that one of the many problems with the code above is not
instantiating the form. I understand what you are trying to do as a plan, but I do not understand your code. My girlfriend writes better code to tell you the truth. Stick to one form calculators for a little
bit longer! And please don't get offended but right now you are asking how to create a nuclear reaction on your first physics class in high school!
Marty
|
| C-Sharp (C#) Group: Re: How do I move
data from a pop up form back to the main
form? |

|
2006-02-08 20:42:18 |
anyway if you create a form with name MyDialogForm then you
declare it
like
MyDialogForm dialogInstanceForm = new MyDialogForm();
if you create a public property/method in the form then you
can call
them
dialogInstanceForm.MyPublicProperty = 10;
or dialogInstanceForm.AddLocation(somelocatininstance);
after you set all those public properties and methods, call
dialogInstanceForm.ShowDialog(this);
in the dialog form code somewhere just say this.Close() and
this will
return the control to the parent.
So the logic flow is
in parent form instantiate the dialog form
set the public properties of the dialog form (like default
text for a
textbox and so forth.)
show the instance as a dialog (.ShowDialog(this))
do whatever you have to do in the instance, saving the
result in public
properties
close the dialog form when it finishes whatever it is doing
by
this.Close() in MyDialogForm's methods
from the parent folder extract any public properties from
the dialog
Let me give you very generalized and on the top of my head
example
(THIS WORKS ONLY LOGICALLY... NOT SYNTAXICALY!):
public class MyMainForm:Form
{
public void SomeButton_Click()
{
MyDialogForm questionDialog = new MyDialogForm();
questionDialog.DefaultValue = "Some default
value to show in
textbox on dialog form";
questionDialog.ShowDialog(this); //you might need
to convert
this to a IWin32Form or something
string result = questionDialog.ReturnValue;
//do whatever you want with the result
}
}
public class MyDialogForm:Form
{
private Textbox textbox1 = new Textbox();
public string DefaultValue="";
public string ReturnValue="";
public MyDialogForm()
{
}
public sub MyDialogForm_Show()
{
textbox1.text = DefaultValue;
}
public sub Button1_Click()
{
ReturnValue = textbox1.value;
}
}
|
|
[1-4]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|