O'Reilly logo

.NET Windows Forms in a Nutshell by Matthew Adams, Ian Griffiths

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required