First you have to realize that containing your properties in a collection will cause them to be grouped together under it, when displayed on your PropertyGrid.
Therefore, having a collection of string
s and another of int
s will break your current structure, of:
- Having pairs of properties (name and ID) grouped together;
- Having all the properties on the root level of the property grid.
Having said that, you could solve issue #1 by making #2 a bit worse.
create two classes:
MyClass
- containing aName
andIID
properties.MyClassCollection
- a container class (most likely using an underlying List).
To mitigate issue #2, you can add code to expand all nodes at initialization as shown here.
If you try this, you will notice that the "containers" (MyClassCollection
and MyClass
) will have some undesired decription text appearing next to them when displayed.
This is where this article comes in handy.
Your property would then be:
[DisplayName("Some info here"),
DescriptionAttribute("Some more descriptive info here...")]
virtual public MyClassCollection MyData { get; set; }
and your class definitions would be along the lines of:
public class MyClass
{
public string Name
{
get { return _name; }
set { _name = value; }
}
public int IID
{
get { return _iid; }
set { if ((64 > value) && (value >= 0)) _iid = value; }
}
private string _name;
private int _iid;
}
public class MyClassCollection : CollectionBase
{
// See the article for code for the overrides (for CollectionBase) and implementation (for ICustomTypeDescriptor)
}
If you look at the article mentioned above, regarding the tweaking of the display text of the container classes, you'll have to make some adjustments to the classes above.