Name

PropertyGrid

Synopsis

This Control will be very familiar to users of the Visual Studio .NET IDE, as it is used to provide the property inspector for objects in the designer. You can use it to provide a similar function in your own applications.

At its simplest, you can assign any object to the SelectedObject property, and it will use reflection to discover the properties and events in your object. You can also set an array of SelectedObjects. The grid will then display only those properties common to the entire array. This should not be confused with the SelectedGridItem property, which returns a GridItem representing the currently selected row in the grid. You can bind to the SelectedGridItemChanged event to receive notification when the selection is modified. As the values in the grid change, the PropertyValueChanged event is raised. If the SelectedObject (or SelectedObjects) changes, the grid will fire SelectedObjectsChanged.

Beyond that, you can use several designer attributes to mark up your target objects for use with the PropertyGrid, including System.ComponentModel.CategoryAttribute, which provides a means of visually grouping properties, and System.ComponentModel.DescriptionAttribute, which displays help text.

A property will appear in the grid unless it is annotated with No. You can customize this behavior by creating a new System.ComponentModel.AttributeCollection (passing an array of Attribute objects in the constructor) and assigning it to the grid’s BrowsableAttributes ...

Get .NET Windows Forms in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.