请问 如何把窗体A中listbox中的内容加载到窗体B中的comboBox中去? 窗体A和B都在同一个命名空间中!

解决方案 »

  1.   

    int iCount = listBox1.Items.Count;
    for(int i = 0;i<iCount;i++)
    {
      comboBox1.Items.Add(listBox1.Items[i]);
    }
      

  2.   

    public class FormA : System.Windows.Forms.Form
    {
       public System.Windows.Forms.ListBox listBox1;
       .........
       private void Function()
       {
          FormB frm = new FormB();
          this.AddOwnedForm(frmB);

          frmB.Show();
       }
    }public class FormB : System.Windows.Forms.Form
    {
        private Function()
        {
           object frm = this.Owner;
           ListBox lstBox = ((FormA)frm).ListBox1;
           
           int iCount = lstBox.Items.Count;
           for(int i = 0;i<iCount;i++)
           {
             this.comboBox1.Items.Add(lstBox.Items[i]);
           }
        }
    }
      

  3.   

    是 WebForm 还是 WinForm 呀。
    WinForm 用 crossbowvic(漫步的兔子) 的就行。
    WebForm 就有点儿讨厌,论坛里有相关的问题,你查查看。
      

  4.   

    是winform,但是兔子的代码 不能通过!
      

  5.   

    如果是窗体A中的按钮点击后打开窗体B的话
    可以在窗体B的构造函数里面加传入参数
    把窗体A中ListBox的项传到窗体B就可以了
      

  6.   

    你可以在B窗口写一个公有方法在A窗口把要加的listbox内容传进去,然后再B窗口中直接添加不就行了?不然你就试下Form里面的Tag属性吧,它可以存一个obj的对象。不过还没见人用过