inherit ControlCollection

Hi all

I have build a custom class that inherits ControlCollection

I have overriden the Add method as follows

public void Add(ArthurControls.ArhturPanel.BaseArhturPanelItem value)
{
    base.Add (value);
}

where value is a usercontrol
when i add some controls to the controlcollection i get the following error

"Value cannot be null.\r\nParameter name: array"

this is the stacktrace
"   at System.Array.IndexOf(Array array, Object value, Int32 startIndex, Int32 count)\r\n   at System.Windows.Forms.ControlCollection.GetChildIndex(Control child, Boolean throwException)\r\n   at System.Windows.Forms.ControlCollection.GetChildIndex(Control child)\r\n   at System.Windows.Forms.Control.UpdateChildZOrder(Control ctl)\r\n 

Does anybody has any idea why this is happening

Thnx!!!!!



Answer this question

inherit ControlCollection

  • heavenly

    The ControlCollection class is very tightly bound to the internals of the Form class.  I don't think it's designed to be used how you are intending to use it.  Could you describe the scenario you're trying to accomplish   

    If you just want a collection of controls that you can store your user controls in, you might consider generating one with the Strongly-Typed collection generator tool available for download on www.gotdotnet.com.  Just go to the User Samples area, and search for "Collection Generator."  You can have it generate a strongly typed collection of type 'Control' which you can add to your project.  You won't even need to overload the Add method for your derived class like you did above... since your derived class inherits from Control.

    Bri


  • inherit ControlCollection