PropertyGrid meets Generics
-
Hello everyone, This may seem like an odd question but here goes. I'm using the PropertyGrid for a project of mine -- works great and I've used the EnumDescConverter and PropertySorter TypeConverters that I found on CodeProject. Basically I have an (older) application (.NET 1.1) that I have moved to .NET 2.0. In the older application, I had a class with a Layers property that contained a collection of Layers. I used the ExpandableObjectConverter to let the PropertyGrid show a + sign beside the layers as well as a list of the layers. This was great. Basically it was something like
public class Config
{
...
private LayerCollection m_Layers = new LayerCollection();[TypeConverter(typeof(ExpandableObjectConverter))]
public LayerCollection Layers
{
get { return m_Layers; }
}
...
}LayerCollection implemented CollectionBase, as well as ICustomTypeDescriptor to show "Layer #" beside each entry. This worked great. Now, however, I'm restructured things so that it looks something like this:
public class Config
{
...
private List<Layer> m_Layers = new List<Layer>();public List<Layer> Layers
{
get { return m_Layers; }
}
...
}If I apply the ExpandableObjectConverter to the Layers properties, it just shows the Count property of the List. Hmmm. Not what I wanted. I know I'm missing something here -- just not sure what. I used the generic List because it was easy -- but now I'm thinking that I may have to go back and have a LayerCollection class again so that it can implement the ICustomTypeConverter. Maybe make that generic so I can reuse it, but still. Any ideas? Has anyone else run into a similar fiasco? Thanks! -Matt
-
Hello everyone, This may seem like an odd question but here goes. I'm using the PropertyGrid for a project of mine -- works great and I've used the EnumDescConverter and PropertySorter TypeConverters that I found on CodeProject. Basically I have an (older) application (.NET 1.1) that I have moved to .NET 2.0. In the older application, I had a class with a Layers property that contained a collection of Layers. I used the ExpandableObjectConverter to let the PropertyGrid show a + sign beside the layers as well as a list of the layers. This was great. Basically it was something like
public class Config
{
...
private LayerCollection m_Layers = new LayerCollection();[TypeConverter(typeof(ExpandableObjectConverter))]
public LayerCollection Layers
{
get { return m_Layers; }
}
...
}LayerCollection implemented CollectionBase, as well as ICustomTypeDescriptor to show "Layer #" beside each entry. This worked great. Now, however, I'm restructured things so that it looks something like this:
public class Config
{
...
private List<Layer> m_Layers = new List<Layer>();public List<Layer> Layers
{
get { return m_Layers; }
}
...
}If I apply the ExpandableObjectConverter to the Layers properties, it just shows the Count property of the List. Hmmm. Not what I wanted. I know I'm missing something here -- just not sure what. I used the generic List because it was easy -- but now I'm thinking that I may have to go back and have a LayerCollection class again so that it can implement the ICustomTypeConverter. Maybe make that generic so I can reuse it, but still. Any ideas? Has anyone else run into a similar fiasco? Thanks! -Matt
Nevermind :) I created a class called ExpandableList<T> that inherits from List<T> AND implements ICustomTypeDescriptor. This is a pretty useful technique, I'll post it as an article soon. -Matt
Bart: Look at me, I'm a grad student. I'm 30 years old and I made $600 last year. Marge: Bart, don't make fun of grad students. They've just made a terrible life choice. -- modified at 22:27 Wednesday 12th July, 2006