Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. PropertyGrid meets Generics

PropertyGrid meets Generics

Scheduled Pinned Locked Moved C#
questioncsharp
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mattman206
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • M Mattman206

      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

      M Offline
      M Offline
      Mattman206
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups