nogChoco

I'm trying to clean up the many properties that my class exposes, and so I'd like to learn how to create a subfolder in the Properties Explorer like the one that a Font has (subtree with Name, Size, Unit, ...). I know I can group by Category and achieve a similar effect, but making a subtree like that, seems like a good technique to know. How is that done







Re: Visual Basic Language SubFolder in Properties Explorer?

PEng1

It's simple, your property must be defined as a class which has subproperties, the designer knows to include the subproperties as part of the property, try it, define a MyFont Property, you will see that you get the subtree containing all of the properties of a Font, this will not work with Types.




Re: Visual Basic Language SubFolder in Properties Explorer?

nogChoco

Hi PEng1,

I'm familiar with that, but I'd like to build a custom subtree (the Name, Size, Unit, ... part of the Font property).

EDIT: According to the Overview of Extending Metadata Using Attributes , they're called nested properties - pretty obvious, but no quick implementation examples to be found Sad





Re: Visual Basic Language SubFolder in Properties Explorer?

PEng1

I understand what you are asking. What I am saying is that it is not possible, the only way to do it is to have a property that is defined by a class also containing properties. For instance if you have the code below, the MyFont Property of MyControl would be displayed with a subtree displaying the nested Property Name. Since Name is defined as a type the IDE knows not to look at any of its properties.

Code Snippet

Public Class MyControl

Public Property MyControlFont() as MyFont

End Property

End Property

Public Class MyFont

Pubic Property Name() as String

End Property

End Class






Re: Visual Basic Language SubFolder in Properties Explorer?

nogChoco

Thank you for your replies, PEng1

Yes, I tried that before and I also expected it to work like you've explained, but it either shows a disabled "WindowsApplication1.MyFont" text, or in another test, it just showed the MyFont properties as normal properties within the MyControl property list.

I found an article on the CodeProject that has examples for building these nested expandable properties and custom property-editors, so I think that will answer it for me, although I haven't tried it yet. Here's the link for reference:

Using PropertyGrid (By Sreenivas Vemulapalli)

EDIT: And I found an MSDN example that is a little simpler than a CodeProject example (for once ):
Getting the Most Out of the .NET Framework PropertyGrid Control (by Mark Rideout)