WinForms PropertyGrid

I'm probably the last person on earth that didn't know that you could use the PropertyGrid in WinForms apps. Well, I found out today, and I'm liking it so far. It doesn't show up by default in the Toolbox, but you can add it with the "Add Items" dialog.

So did you know that you can bind the PropertyGrid to an object? Further, it works exactly the same way that VS design-time support works. This means that you can decorate your objects with attributes from the System.ComponentModel namespace, and they will affect how the properties are displayed inside the grid. Don't want a property to show up? Well <ComponentModel.Browsable(False)> is for you. Want it to display neat little tips in the help space at the bottom? Use the Description attribute.

I can't wait to play with this some more.

4 Comments

  • Everything about the propertygrid is great, except for one thing, there is no way to tab between properties inside the grid.



    This is a problem that can be fixed (CodeSmith has a propertygrid that allows this), but until I get around to actually figuring it out and coding it, it is still an annoying little problem.

  • There's no &quot;tabbing&quot; between properties because it's essentially a grid control. You navigate with the cursor keys.

  • I understand that the PropertyGrid control provided by Microsoft does not allowing tabbing between Properties. I find this very annoying.



    Get Codesmith and try the &quot;modified&quot; PropertyGrid control inside the program that allows tabbing between properties.



    In my opinion the Codesmith PropertyGrid is far more intuitive and easier to use than the standard PropertyGrid.

  • I fell in love with the PropertyGrid when I first discovered it, I thought it would be great for providing a UI for &quot;user preferences&quot; in my application. Until I ran into its big limitation - it does not work in a security-restricted environment. I suspect that this is the reason it is the only control that is not in the toolbox by default.

    When I say &quot;security restricted environment&quot; - I mean any environment where reflection is not allowed. For example, if your app is a &quot;no touch deployment&quot; executable launched directly from a web page (as mine is).

Comments have been disabled for this content.