VS2005: Collection properties not serialised by designer on custom controls

  • Thread starter Thread starter Martin Robins
  • Start date Start date
M

Martin Robins

I have developed a custom control that, among others, includes a property that is a collection of "Items".

If I place an instance of my control onto a CF form, I can view all of the properties correctly in the property grid and my collection appears with the ellipses ready to open the collection editor. Click on the ellipses and the editor opens correctly and I can add and remove items in the collection.

Unfortunately, the incorrect code is generated when I close the designer, an example is below ...
//
// switchboard
//
this.switchboard.DisabledItemAction = TechnicalDirect.Windows.Forms.SwitchboardDisabledItemAction.Hide;
this.switchboard.Dock = System.Windows.Forms.DockStyle.Fill;
this.switchboard.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Regular);
this.switchboard.ItemHeight = 48;
this.switchboard.Location = new System.Drawing.Point(0, 0);
this.switchboard.Name = "switchboard";
this.switchboard.SelectedIndex = 0;
this.switchboard.Size = new System.Drawing.Size(312, 192);
this.switchboard.TabIndex = 0;
this.switchboard.Click += new System.EventHandler(this.switchboard_Click);
//
// switchboardItem1
//
this.switchboardItem1.Image = ((System.Drawing.Image)(resources.GetObject("switchboardItem1.Image")));
this.switchboardItem1.Location = new System.Drawing.Point(0, 0);
this.switchboardItem1.Name = "switchboardItem1";
this.switchboardItem1.Size = new System.Drawing.Size(200, 200);
this.switchboardItem1.TabIndex = 0;
this.switchboardItem1.Text = "Logon";
Whilst this code looks fine, it is actually missing the part where the SwitchboardItem instance is added to the SwitchboardItems collection of the Switchboard control ...
this.switchboard.SwitchboardItems.Add(this.switchboardItem1);
Has anybody seen this before, and if so, can you point me toward what I may have done wrong? I have not implemented any custom designers and my DesignTimeAttributes.xmta file contains an entry for the control with only the DesktopCompatible attribute specified.

Thanks.
 
For anybody else that sees this problem, the answer is to specify <DesignerSerializationVisibility>DesignerSerializationVisibility.Content</DesignerSerializationVisibility> within the <Property name=""> tag.

"Martin Robins" <martin dot robins at technicaldirect dot co dot uk> wrote in message I have developed a custom control that, among others, includes a property that is a collection of "Items".

If I place an instance of my control onto a CF form, I can view all of the properties correctly in the property grid and my collection appears with the ellipses ready to open the collection editor. Click on the ellipses and the editor opens correctly and I can add and remove items in the collection.

Unfortunately, the incorrect code is generated when I close the designer, an example is below ...
//
// switchboard
//
this.switchboard.DisabledItemAction = TechnicalDirect.Windows.Forms.SwitchboardDisabledItemAction.Hide;
this.switchboard.Dock = System.Windows.Forms.DockStyle.Fill;
this.switchboard.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Regular);
this.switchboard.ItemHeight = 48;
this.switchboard.Location = new System.Drawing.Point(0, 0);
this.switchboard.Name = "switchboard";
this.switchboard.SelectedIndex = 0;
this.switchboard.Size = new System.Drawing.Size(312, 192);
this.switchboard.TabIndex = 0;
this.switchboard.Click += new System.EventHandler(this.switchboard_Click);
//
// switchboardItem1
//
this.switchboardItem1.Image = ((System.Drawing.Image)(resources.GetObject("switchboardItem1.Image")));
this.switchboardItem1.Location = new System.Drawing.Point(0, 0);
this.switchboardItem1.Name = "switchboardItem1";
this.switchboardItem1.Size = new System.Drawing.Size(200, 200);
this.switchboardItem1.TabIndex = 0;
this.switchboardItem1.Text = "Logon";
Whilst this code looks fine, it is actually missing the part where the SwitchboardItem instance is added to the SwitchboardItems collection of the Switchboard control ...
this.switchboard.SwitchboardItems.Add(this.switchboardItem1);
Has anybody seen this before, and if so, can you point me toward what I may have done wrong? I have not implemented any custom designers and my DesignTimeAttributes.xmta file contains an entry for the control with only the DesktopCompatible attribute specified.

Thanks.
 
Back
Top