clear时判断 那个对象为null

解决方案 »

  1.   

    foreach (Control c in form1.Controls)
            {
                if (c is ListBox)
                { 
                    ListBox lb = c as ListBox;
                    if (lb != null && lb.Items.Count != 0)
                    {
                        lb.Items.Clear();
                    }
                }
            }
      

  2.   

    你出现异常的时候要会看提示。异常信息,和ex的InnerException很重要。
      

  3.   


    求现成中委托处理listbox的代码可用实例。谢谢