Well. A form is an object like any other object in c#, and you have many options. However, lets assume you're going to make a phonelist holder of your friends. On the main form you want a list maybe of names, so you can quickly find the person you're after. The second form holds more details, such as address, phone number, date of birth, stuff like that.
If you make a class to hold all that data, you can pass it as a single contained lump much like handing a cup of coffee over, you dont ask someone if they want one, and then hand over 1 cup a handful of hot water, ground stuff, maybe a dribble of milk and some sugar do you?
Then what you can do is setup a function to call in your second "details" form, where you send it the class as parameter, which can then populate the details form, and everyones happy.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
Well..
void DataInit(myclass data)
{
if (data!=null)
{
txName.Text=Data.Name;
txtAge.Text=Data.Age;
txtAddress.Text=Data.Address;
}
else
{
txName.Clear();
txAge.Clear();
txAddress.Clear();
}
}
There are a ton of alternatives.
For example, to be honest, you could make the form part of the data class, as its going to display it, you could make the data a property on the form and when it changes it knows to update the form..
A fickle instructor is a *good* thing.
Now, the way Ive suggested is semi OK, but obviously its not going to return the data to your form. If you want that you could of course pass by reference.
LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
public int STR
{
get
{
return str;
}
set
{
str = strBox.Text;
}
}
This looks like a property to me, but your syntax is not correct
do it this way:
private string str;
public string STR
{
get
{
return str;
}
set
{
str = value; }
}
To get the string : Myclass.str
To set the string : Myclass.str = strBox.Text;
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
thanks for the reference ddanbe :-)
just so happened to coincide with me posting
dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143