UserControls/Design Time Property Grid

I'm designing and UserControl with a lot of properties.  I would like to place some of the porperties in sub catagories.  Similar to the way the X,Y properties are displayed for the Location property under the Layout catagory.  Can someone help me emulate this behavior.  Thanks Robert

Answer this question

UserControls/Design Time Property Grid

  • John RWB

    Sure...
    you can supply a TypeConverter attribute to a property. The TypeConverter will convert your datatype to a string a vice versa. This is the string that is displayed next to your property. A typeconverter can also tell the propertygrid what properties are available for editing. That's where the ExpandableObjectConverter comes into play: it is derived from TypeConverter and implements default behaviour for exposing sub-properties.

    Does that make any sense

    Let's assume you set the SelectedObject of your propertygrid to some instance of object Foo, which has a property of type Bar. In this example the propertygrid will display a property Bar, in the category "SomeCategory", and you can open it up because the class has the ExpandableObjectConverter applied to it.



    [TypeConverterAttribute( typeof( ExpandableObjectConverter ) )]
    public class Bar
    {
       public string Name
       {
          get { return m_Name; }
          set { m_Name = value; }
       }

       public int SomeValue
       {
          get { return m_SomeValue; }
          set { m_SomeValue; }
    }

    public class Foo
    {
       [Category("SomeCategory")]
       public Bar Bar
       {
          get { return m_Bar; }
          set { m_Bar = value; }
       }
    }

     


    I would further suggest browsing for ExpandableObjectConverter and TypeConverter in the docs and on google, there are lots of articles on the subject.

    Does this answer your question

  • Dharmesh Vora

    Hi!

    Thanks for asking! I'm a member of the ASP.NET team, and was just popping over here to see what was going on. The best place to ask ASP.NET questions is over on the ASP.NET forums at http://www.asp.net/welcome.aspx tabindex=1&tabid=39

    One way you could do that is put the properties that you want to categorize into their own class, thus providing myClass.subClass.property = "hello";

    HTH,

    PEte



  • Branco Medeiros

    You can do so by providing a category attribute to your property. For instance:

    [Category("Layout")]
    public Point Location
    {
       get { return m_Location; }
    }

    If you plan to use separate classes to bundle properties, use the ExpandableObjectConverter attribute on the class in order to be able to open a sub-item in the propertygrid.

    Hope this helps



  • stakei

    Could you tell more about how to use the ExpandableObjectConverter attribute
  • UserControls/Design Time Property Grid