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

dotnet windows forms designtime

group:

Custom Object Collection Editors


Custom Object Collection Editors ShiveleyTom
10/15/2006 7:01:02 PM
dotnet windows forms designtime:
I am attempting to make any Array or Collection properties I create in my
UserControls or Components editable through the PropertyGrid during design
time.
First, how do I make the results of adding objects through the editor to be
saved into the member storing the Array or Collection?
Also, I would like to know how to attach Arrays of objects similar to how
Columns are linked to Tables or DataGrid objects through the collection
editor.
I have been able to successfully make the properties Browsable by the
PropertyGrid, but now having trouble making the next steps work properly.

Re: Custom Object Collection Editors Bernd S
10/18/2006 3:05:43 PM
Here is an example from my code:

If your collection is named "MyCollection":

- add an EditorAttribute to your collection's constructor:

[Editor(typeof(MyCollectionEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public class MyCollection : CollectionBase

- implement the CollectionEditor, where you can override CreateNewItemTypes:
public class ControlSpecCollectionEditor : CollectionEditor
{
protected override Type[] CreateNewItemTypes()
{
return new Type[3] { typeof( ElemA), typeof( ElemB), typeof( ElemC) };
}
}

- mark the collection property as DesignerSerializationVisibility.Content
[DesignerSerializationVisibility( DesignerSerializationVisibility.Content )]
public MyCollection MyElements
{
get
{
return ...
}
}

Hope that helps.

AddThis Social Bookmark Button