2.一个如果是主表格 3.另一个表格是在运行时由主表格创建的 在MainForm中: private OtherForm otherForm; private ListBox otherFormListBox; private void MainForm_Load(对象发件人,EventArgs e) { otherForm = new OtherForm; otherFormListBox = otherForm.OFListBox; otherForm.Show(); // 在此处显示? } public void TransferData() { // 做正确的事 } 在OtherForm中: public ListBox OFListBox; private ListBox otherFormListBox; private void OtherForm_Load(对象发件人,EventArgs e) { otherForm = new OtherForm; OFListBox = listBox1; } 在这个例子中,你在另一个Form中公开ListBox,所以Main Form可以访问它。 Hello,I am trying to transfer my data from listbox that the user has entered into a different listbox on another page. For example I want the ID from Window1 Listbox1 to be transferred to Window2 Listbox2. I have set up a class to store the data but I am unsure how to transfer the data over. (Edit I don't know any of the code on how to transfer the ID from one window to another)Kind regardsWhat I have tried:Class:class TrainF { private List<TrainF> _list = new List<TrainF>(); public void Add(TrainF Details) { _list.Add(Details); } //Setting the data for the train booking to be stored. private string TrainID; public string ID { get { return TrainID; } set { TrainID = value; } }Main code:TrainF aPerson = new User(); aPerson.ID = ID.Text;try { if (TxtTrainID.Text == "") { throw new System.ArgumentException("You must enter your a train ID"); } } catch (ArgumentException ex) { MessageBox.Show(ex.Message); } LstTrain.Items.Add(TxtTrainID.Text); 解决方案 这篇关于如何使用列表框将数据从一个窗口传输到另一个窗口。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-15 00:40