各位好:
小弟问一小问题,请各位帮忙解决.
假设有两窗体A ,B
A窗体中有空间 listbox1 ,button1,
B窗体中有空间 listbox2 ,button2,
我现在想实现的是想在A窗体中通过点button1 ,显示窗体B,在B中做些操作,然后再把B窗体中的
listbox2的所有项全部回传到A并在listbox1中显示 ,
好象有个showdialog()的方法,请赐教!
小弟问一小问题,请各位帮忙解决.
假设有两窗体A ,B
A窗体中有空间 listbox1 ,button1,
B窗体中有空间 listbox2 ,button2,
我现在想实现的是想在A窗体中通过点button1 ,显示窗体B,在B中做些操作,然后再把B窗体中的
listbox2的所有项全部回传到A并在listbox1中显示 ,
好象有个showdialog()的方法,请赐教!
http://blog.csdn.net/Knight94/archive/2006/08/22/1104957.aspx
FormB b = new FormB(listBoxA)
b.Show();//或者ShowDialog();也可以FormB:
ListBox refListBoxA;//定义一个引用,指向FormA中的listBoxA;
public FormB(ListBox listBoxA)//构造函数接受一个ListBox实例
{
this.refListBoxA = listBoxA;
//其他初始化代码;
}
//FormB中可以对refListBoxA进行任何操作,且对其的修改可以影响到FormA
{
B b = new B();
if (DialogResult.OK == b.ShowDialog())
{
//获取list2的数据
for (int i = 0 ; i < b.listBox2.GetItemCount(); ++i)
{
for (int j = 0 ; j < b.listBox2.GetColumnCount(); ++j)
{
string s = b.listBox2.GetItemText(i,j);
}
}
}
}
这里的第二个例子