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