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. How to Use PropertyGrid for Complex Class

How to Use PropertyGrid for Complex Class

Scheduled Pinned Locked Moved C#
announcementgraphicsdesignhelptutorial
3 Posts 2 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.
  • A Offline
    A Offline
    Anindya Chatterjee
    wrote on last edited by
    #1

    Suppose I have the following class :

    public class A
    {
    public bool Boolean {get; set;}

    public List<B> ListOfB {get; set;}
    }

    public class B
    {
    public String StringValue {get; set;}

    public List<String> OneList {get; set;}

    public List<String> AnotherList {get; set;}
    }

    I want to expose the class A and under it the B class in a propertygrid. I have tried a lot of thing, but no help. May be I am missing something. What I did is as follows :

    [DefaultProperty("ListOfB")]
    public class A
    {
    [Browsable(false)]
    public bool Boolean {get; set;}

    [Category("Visuals")]
    [Description("YZYZYZ")]
    [MergableProperty(false)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [Localizable(true)]
    [Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
    [Editor(typeof(BListEditor), typeof(UITypeEditor))]
    public List<B> ListOfB {get; set;}

    }

    public class B
    {
    public String StringValue {get; set;}

    [Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
    [Category("Visuals")]
    [Description("XXYZ")]
    [MergableProperty(true)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public List<String> OneList {get; set;}

    [Description("PPPWRT")]
    [MergableProperty(true)]
    [Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
    [Category("Visuals")]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    public List<String> AnotherList {get; set;}
    }

    public class BListEditor : CollectionEditor
    {
    public BListEditor()
    : base(typeof(List<B> ) )
    { }

    protected override Type[] CreateNewItemTypes()
    {
    return new Type[] {typeof(B)};
    }

    protected override object SetItems(object editValue, object[] value)
    {
    // Cast the context into the expected control type
    A settings = (A)Context.Instance;
    // Let base class update the collection
    object ret = base.SetItems(editValue, value);

      return ret;
    

    }
    }

    I ha

    H 1 Reply Last reply
    0
    • A Anindya Chatterjee

      Suppose I have the following class :

      public class A
      {
      public bool Boolean {get; set;}

      public List<B> ListOfB {get; set;}
      }

      public class B
      {
      public String StringValue {get; set;}

      public List<String> OneList {get; set;}

      public List<String> AnotherList {get; set;}
      }

      I want to expose the class A and under it the B class in a propertygrid. I have tried a lot of thing, but no help. May be I am missing something. What I did is as follows :

      [DefaultProperty("ListOfB")]
      public class A
      {
      [Browsable(false)]
      public bool Boolean {get; set;}

      [Category("Visuals")]
      [Description("YZYZYZ")]
      [MergableProperty(false)]
      [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
      [Localizable(true)]
      [Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
      [Editor(typeof(BListEditor), typeof(UITypeEditor))]
      public List<B> ListOfB {get; set;}

      }

      public class B
      {
      public String StringValue {get; set;}

      [Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
      [Category("Visuals")]
      [Description("XXYZ")]
      [MergableProperty(true)]
      [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
      public List<String> OneList {get; set;}

      [Description("PPPWRT")]
      [MergableProperty(true)]
      [Editor("System.Windows.Forms.Design.StringCollectionEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(System.Drawing.Design.UITypeEditor))]
      [Category("Visuals")]
      [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
      public List<String> AnotherList {get; set;}
      }

      public class BListEditor : CollectionEditor
      {
      public BListEditor()
      : base(typeof(List<B> ) )
      { }

      protected override Type[] CreateNewItemTypes()
      {
      return new Type[] {typeof(B)};
      }

      protected override object SetItems(object editValue, object[] value)
      {
      // Cast the context into the expected control type
      A settings = (A)Context.Instance;
      // Let base class update the collection
      object ret = base.SetItems(editValue, value);

        return ret;
      

      }
      }

      I ha

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      It sounds like the ExpandableObjectConverter might be what you need. You can look that up on MSDN, or Google for it (you'll get lots of hits). Take a look at Add Custom Properties to a PropertyGrid[^], it shows several methods to get what it sounds like you want to do.

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      A 1 Reply Last reply
      0
      • H Henry Minute

        It sounds like the ExpandableObjectConverter might be what you need. You can look that up on MSDN, or Google for it (you'll get lots of hits). Take a look at Add Custom Properties to a PropertyGrid[^], it shows several methods to get what it sounds like you want to do.

        Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

        A Offline
        A Offline
        Anindya Chatterjee
        wrote on last edited by
        #3

        Thanks I'll try

        Anindya Chatterjee -------------------------------------------------------- 1. Don't Visit ..[^] 2. But Watch ..

        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