我有两个表单,从子表单中我有一个列表框,它通过同一表单上的其他内容获取信息。我希望能够将该列表框中的所有信息发送到主/父表单上的列表框中。通过按钮单击带有标记来发回信息。 在儿童表格上:
private void btnToMain_Click(object sender, EventArgs e)
{
//send info back to Main to be placed in listBoxMain
if (listBoxChild.Items != null)
{
foreach ( string item in listBoxChild.Items)
//I'm not sure what should go here to get all of the items to return
//I think it should be part of my ClassItem which is a class
this.Tag = this.listBoxChild.SelectedItem as ClassItem;
this.DialogResult = DialogResult.OK;
}
}
在主/父表格上:
private void btnFormChild_Click(object sender, EventArgs e)
{
//open new child form
Form2 child = new Form2();
//receive info
if (child.ShowDialog() == DialogResult.OK)
{
ClassItem d = child.Tag as ClassItem; //ClassItem is a public class
if (d != null)
{
//put info into listbox
listBoxMain.Items.Add(d);
}
}
}