all groups > dotnet windows forms designtime > august 2006 >
You're in the

dotnet windows forms designtime

group:

adding designtime support for property of usercontrol (InitializeComponents)


adding designtime support for property of usercontrol (InitializeComponents) Robert Ludig
8/16/2006 9:08:37 AM
dotnet windows forms designtime:
I have a very simple UserControl (derived from
System.Windows.Forms.UserControl) that contains several ListViews. The
UserControl exposes a single public property:

public ListView.ColumnHeaderCollection Columns { get {...} };

When I use VS2005 designer's proprtygrid for that UserConrol to add new

Colums to the Collection everything works fine: The form that contains
the UserControl gets new members ( private
System.Windows.Forms.ColumnHeader columnHeader1, ...) in the
UserControl.Designer.cs also initializes each ColumnHeader inside
InitializeComponets().

There is one thing though that the designer fails to do: it does not
add the necessary:

this.userControl1.Columns.AddRange(new
System.Windows.Forms.ColumnHeader[]
{this.columnHeader1,this.columnHeader2,...});

into the InitializeComponent() Method in the UserControl.Designer.cs.

What do I need to do to make that happen ?
Re: adding designtime support for property of usercontrol (InitializeComponents) Charles Jenkins
8/16/2006 5:43:13 PM
On 2006-08-16 12:08:37 -0400, "Robert Ludig"
<schwertfischtrombose@gmx.de> said:
[quoted text, click to view]

I am a total noob, so this may not help...

I had a control that would not save its items, and was able to cure
that with this procedure:

1. Right-click on the control's source file in the Solution Explorer
2. Choose 'Class Diagram' to enter the UML-like view
3. In the class's diagram, click on the property you are having trouble
with (in this case, Columns)
4. In the Property Inspector, look for 'Custom Attributes' and double-click it
5. In the text area that appears, enter:

DesignerSerializationVisibility(DesignerSerializationVisibility.Content)

If that isn't enough then one more thing to try (even tho it prolly
won't help) would be to add this method:

private bool ShouldSerializeColumns() {
return ( Columns.Count > 0 );
}

Good luck!

AddThis Social Bookmark Button