Expose Property of Constituent Control in UserControl
-
I have a custom control derived from the UserControl class. I have three controls in the container; label, treeview, and toolstrip. I want to expose the Items collection of the toolstrip so that the user can add objects at design-time. When I add the custom control to a form and click the exposed Items collection in properties, I get the following error message: "Value cannot be null. Parameter name: value." I've exhausted all my resources and would appreciate any help anyone can give on this issue. I have provided my property code snippet I used in my custom usercontrol.
private System.Windows.Forms.ToolStrip toolstrip; ... public ToolStripItemCollection Items { get { if (toolstrip == null) { toolstrip = new ToolStrip(); } return (toolstrip.Items); } set { toolstrip.Items.Clear(); foreach (ToolStripItem obj in value) { toolstrip.Items.Add(obj); } } }
-
I have a custom control derived from the UserControl class. I have three controls in the container; label, treeview, and toolstrip. I want to expose the Items collection of the toolstrip so that the user can add objects at design-time. When I add the custom control to a form and click the exposed Items collection in properties, I get the following error message: "Value cannot be null. Parameter name: value." I've exhausted all my resources and would appreciate any help anyone can give on this issue. I have provided my property code snippet I used in my custom usercontrol.
private System.Windows.Forms.ToolStrip toolstrip; ... public ToolStripItemCollection Items { get { if (toolstrip == null) { toolstrip = new ToolStrip(); } return (toolstrip.Items); } set { toolstrip.Items.Clear(); foreach (ToolStripItem obj in value) { toolstrip.Items.Add(obj); } } }
gklas wrote:
set { if (value == null) return; toolstrip.Items.Clear(); foreach (ToolStripItem obj in value) { toolstrip.Items.Add(obj); }
There's obviously some code that's passing in a null, so check for it.
Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
-
gklas wrote:
set { if (value == null) return; toolstrip.Items.Clear(); foreach (ToolStripItem obj in value) { toolstrip.Items.Add(obj); }
There's obviously some code that's passing in a null, so check for it.
Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
Obviously so and it is being checked for. I am assumming that the Toolstrip's internal Items collection is not be intialized, but when I go and review the code for the Toolstrip class, you will see that the Items property instantiates the collection if null. Therefore, there should be no null value. Considering that the Designer uses reflection, I am wondering is there is a code path that is not being called in design-time. Any thoughts?