Hi, I've just started using the PropertyGrid control. The class that is being displayed in the grid is hierarchical. I have decorated all the necessary classes with the ExpandableObjectConverter and other required attributes. I can easily deserialize an Xml file into an instance of the class and display it on the grid. However, i run into issues when i try to add objects into the grid.
For example, lets say the class hierarchy is as shown below (simplfied)
public class Configuration
{
private Source source;
private Target[] targets;
//and associated getters and settes
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Source
{
//some properties
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Target
{
//some simple properties
private int a;
private string b;
//a complex property
private Parameters params;
}
[TypeConverter(typeof(ExpandableObjectConverter))]
public class Parameters
{
//properties here
}
Now if i have a sample file where i have , say, 5 targets , it deserializes nicely and expands the objects in the grid.
The problem appears when i click the associated "browse" button next to the Targets. It shows me an editor where there is an array of 5 target objects and their properties and then has the "Add" and "Remove" buttons at the bottom. Now when i want to add another target object , say, the 6th object, (which wasnt in the file), it creates a new empty Target object but the Parameters is not expandable. It shows a simple property as though the expandable property wasnt set on the class.
So, if i want the Parameters object to be expandable when i add new Targets to the collection what do i have to do?
do i have to implement some kind of an AddTargets() method on the Configuration class which instantiates the Target and its associated children at runtime and adds the attributes on the fly as well?
Any ideas?
Rgds
benjy