C#怎么把集合的值传给另个窗体

来源:百度知道 编辑:UC知道 时间:2024/07/07 07:08:40
Form1:
ArrayList BabyCols = new ArrayList();
......
cb.Address = this.textBox1.Text.ToString().Trim();
cb.Encoding = this.textBox2.Text.ToString().Trim();
cb.MotherName = this.textBox3.Text.ToString().Trim();
cb.FatherName = this.textBox4.Text.ToString().Trim();
cb.Sex = comboBox1.SelectedItem.ToString();
cb.Tz = Double.Parse(this.textBox5.Text.ToString());
cb.HlID = comboBox2.SelectedItem.ToString();
cb.OctID = comboBox3.SelectedItem.ToString();

BabyCols.Add(cb.MotherName);
BabyCols.Add(cb.Address);
BabyCols.Add(cb.Encoding);
BabyCols.Add(cb.FatherName);
BabyCols.Add(cb.Sex);
BabyCols.Add(cb.Tz);
Baby

其实你自己已经做好了阿,只是稍差一点点. 你看你Form2已经有个重载的构造函数.只是参数没有弄完整:
public Form2(IEnumerable ie):this(){
System.Collections.IEnumerator enumerator = ie.GetEnumerator();
while (enumerator.MoveNext())
{
//Do something here.
//Console.WriteLine(enumerator.Current);
}
}
这样就可以直接将Form1的ArrayList 传递到Form2 like this:
Form2 subForm = new Form2(BabyCols);
subForm.Show();

- -#你做WEB出身的吧..还是WEB传值思路...

如果是做WINFORM的话...干吗要传值呢,你直接调用方法不就好了么!

实例化以后把你这个ARRAYLIST直接做参数不就完了!

FORM2 FM2 = NEW FORM2();
FORM2.SOMEFUNCTION(ARRARYLIST MYLIST)
FM2.SHOW();

真是崩溃!!!!!

使用窗体之间的传值啊!两种方法!

定义一个公共的类,里面写全局代码