oneof.us

c#

Programming: PropertyGrid

by Carl on Jun.15, 2007, under .net, c#, development

While coding up some PoC (proof of concept) for a new side-gig, I finally got around to using the PropertyGrid control in Visual Studio .net (thanks Dan for bringing this control to my attention). If you’ve ever used Visual Studio .net, you’ll immediately recognize this control, even if you didn’t know its name. Here’s a screen-clip of the property grid in action on a Form control:

PropertyGrid

Now the cool thing about this control is that you can incorporate it into your own app very easily:

  1. Create a class with public properties
  2. In your Form1 Desginer, drag a PropertyGrid control from the toolbox (if it’s not on your toolbox, check here)
  3. Open the Form1.cs class and add the following line: propertyGrid1.SelectedObject = yourObjectName;

That’s it! To add categories, descriptions, etc to the PropertyGrid, check out the lower half of this page on c-sharpcorner.com, it goes into the appropriate attributes you can use (most of the time, they tell you to append ‘Attribute’ to your attribute names, but listen to intellisense, it will omit that).

Here’s a screenshot of a custom class I made with a few properties, bound to a PropertyGrid control:

PropertyGrid

2 Comments more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...