你可这样作嘛public ListItemCollection MyItems
{
get{
return listbox1.Items
}
}至于第二个,你可以在整个类中定义一个listbox的对象,重载CreateChildControls方法时,只是将其加入实例化后加到集合中就可以了。

解决方案 »

  1.   


    public ListItemCollection MyItems
    {
    get{
         EntrueCreateControls();
         listbox d = (listbox) this.findcontrol("listbox1的ID");       
         if(d==null)
          return null;
         else
             return d.items
        } 
    }
      

  2.   

    ==>有由于那二个ListBox控件是在CreateChildControls方法中添加的,在这个函数外又得不到ListBox控件的引用前一个就不多说了!这个你可以在空间里面声明一个private的ListBox但是不要实例化,你在CreateChildControls里面再实例化它这样就可以在函数的外面的到这个ListBox的引用了!
      

  3.   

    对所有的子控件的属性进行读取或设置时,一律加上EntrueCreateControls();public override ListItemCollection Items
    {
    get{ 
          EntrueCreateControls();
          return listbox2.Items;
        }
    }
      

  4.   

    昨天忘了加EnsureChildControls()zhongkeruanjian(编程亮子)和 wacle([Smile!]) 打错了不是EntrueCreateControls()(不存在)
    是EnsureChildControls()