I have 3 forms: form1(which I want to use my List from form3 in which I create List and Add things to it), form2 ( which contains a button to go back to form1 and a button to go to form3 and get values to the list.
I tried creating the following class:
public class ListArticle
{
public List<string> Clothes { get; private set; }
public List<string> Colors { get; private set; }
public ListArticle()
{
Clothes = new List<string>();
Colors = new List<string>();
}
}
and then declare trying Adding things in the List from form3 like this:
// This is the Declaration
public ListArticle _articles = new ListArticle();
public ListArticle Articles
{
get
{
return _articles;
}
set
{
_articles = value;
}
}
This is how I add:
_articles.Clothes.Add("T-shirt " + tshirt_number.ToString());
_articles.Colors.Add(closestColor2(clist, color));
and this is how I am trying to get the values:
when I close form3
I do this:
Form2 frm = new Form2();
frm.Show();
Articles = _articles;
this.Hide();
in form2 I do nothing..
and in form1 I tried to do it like this:
//declaration
public ListArticle Articles;
public ListArticle _articles
{
get
{
return Articles;
}
set
{
Articles = value;
}
}
//and this is how I tried to do it but it returns null everytime.
private void button3_Click(object sender, EventArgs e)
{
try
{
Form3 f = new Form3();
f.Articles = Articles;
foreach (string c in Articles.Clothes)
{
MessageBox.Show(c);
}
}
catch
{
MessageBox.Show("Articles is null.");
}
}