Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Expose Property of Constituent Control in UserControl

Expose Property of Constituent Control in UserControl

Scheduled Pinned Locked Moved C#
helpdesigndocker
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xfitr2
    wrote on last edited by
    #1

    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);
        }
      }
    }
    
    C 1 Reply Last reply
    0
    • X xfitr2

      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);
          }
        }
      }
      
      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      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 )

      X 1 Reply Last reply
      0
      • C Christian Graus

        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 )

        X Offline
        X Offline
        xfitr2
        wrote on last edited by
        #3

        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?

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups