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.
Thank you.
Bernd S - 18 Oct 2006 14:05 GMT
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.