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. Property in custom control inserts unnecessary lines in designer code

Property in custom control inserts unnecessary lines in designer code

Scheduled Pinned Locked Moved C#
csharpcssquestion
5 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.
  • J Offline
    J Offline
    jbrammeier
    wrote on last edited by
    #1

    I have a custom control in C# and one of the properties is an internal class that consists of a list of another class. The control and the class work fine, except that every time I touch a form on which the control exists, it adds extraneous lines to the designer code. Here's the property in the control. The DefaultValue is null, so my assumption is that it should not create anything in the designer code:

    private PopupTable gridColumns = null;
    \[Category("Appearance"), Description("Collection of Columns to show in grid"), 
            DesignerSerializationVisibility( DesignerSerializationVisibility.Visible),     DefaultValue(null)\]
    public PopupTable GridColumns
    {
        get { return gridColumns; }
        set 
        {
            if (value != null) gridColumns = value;
        }
     }
    

    Here's what it inserts into the designer code in a VB form:

    New fctgControls2.PopupTable.Add(PopupColumn1)
    New fctgControls2.PopupTable.Add(PopupColumn2)
    New fctgControls2.PopupTable.Add(PopupColumn3)
    New fctgControls2.PopupTable.Add(PopupColumn4)

    So, every time I touch a form, I have to go in and remove this junk from the designer code. After that, the app works fine. Any ideas?

    D 1 Reply Last reply
    0
    • J jbrammeier

      I have a custom control in C# and one of the properties is an internal class that consists of a list of another class. The control and the class work fine, except that every time I touch a form on which the control exists, it adds extraneous lines to the designer code. Here's the property in the control. The DefaultValue is null, so my assumption is that it should not create anything in the designer code:

      private PopupTable gridColumns = null;
      \[Category("Appearance"), Description("Collection of Columns to show in grid"), 
              DesignerSerializationVisibility( DesignerSerializationVisibility.Visible),     DefaultValue(null)\]
      public PopupTable GridColumns
      {
          get { return gridColumns; }
          set 
          {
              if (value != null) gridColumns = value;
          }
       }
      

      Here's what it inserts into the designer code in a VB form:

      New fctgControls2.PopupTable.Add(PopupColumn1)
      New fctgControls2.PopupTable.Add(PopupColumn2)
      New fctgControls2.PopupTable.Add(PopupColumn3)
      New fctgControls2.PopupTable.Add(PopupColumn4)

      So, every time I touch a form, I have to go in and remove this junk from the designer code. After that, the app works fine. Any ideas?

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      This normally happens by being set in a default constructor. Have you checked there?

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

      J 2 Replies Last reply
      0
      • D DaveyM69

        This normally happens by being set in a default constructor. Have you checked there?

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

        J Offline
        J Offline
        jbrammeier
        wrote on last edited by
        #3

        The default constructor creates a new list. So you're saying if I move that code to another method and leave the default constructor blank, that should take care of it? I'll try that.

        1 Reply Last reply
        0
        • D DaveyM69

          This normally happens by being set in a default constructor. Have you checked there?

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

          J Offline
          J Offline
          jbrammeier
          wrote on last edited by
          #4

          It wasn't quite that straightforward, but that was essentially the problem. Some of the controls were inherited from that base control and there was code in the OnLoad event to initialize the collection. I surrounded that code with

          if (!DesignMode)
          {
          }

          That took care of it. Thanks for your help.

          D 1 Reply Last reply
          0
          • J jbrammeier

            It wasn't quite that straightforward, but that was essentially the problem. Some of the controls were inherited from that base control and there was code in the OnLoad event to initialize the collection. I surrounded that code with

            if (!DesignMode)
            {
            }

            That took care of it. Thanks for your help.

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            No problem :-D

            Dave
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

            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