المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Expose Property of Constituent Control in UserControl



C# Programming
05-06-2009, 02:50 AM
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);
}
}
}