Customizing Display Names

By default, the labels shown next to each property display the property name. This works fine in many cases, but you may want to customize the display to provide more descriptive names. The easiest way to achieve this is to decorate the properties on the object with custom attributes and by setting the Name property in the Display attribute (note that the Display attribute is defined in the System.ComponentModel.DataAnnotations namespace, in the System.ComponentModel,DataAnnotations assembly).

For example, you could define the Display attribute in the class itself and set the value for the Name property as in the following code:

      Visual Basic

      C#

The C1PropertyGrid uses this additional information and displays the customer as shown below:

 

 

This method requires that you have access to the class being displayed in the C1PropertyGrid. If you want to change the display strings but cannot modify the class being shown, then you would have to use the PropertyAttributes property to provide explicit information about each property you want to show on the C1PropertyGrid.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.