When you bind an object to the PropertyGrid, it allows you to set the display name for each property you add for that object to be displayed at runtime. This can be easily achieved at design-time by following these steps:
By default, the labels shown next to each property display the property names. 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 customize the object properties with custom attributes.
The following image shows how PropertyGrid appears after customizing the display name:
To customize the display names, you could define the DisplayAttribute in the class itself and set the value for the Name property as in the following code. The following example uses the sample created in Quick Start for binding PropertyGrid to a class.
C# |
コードのコピー
|
---|---|
public class Customer { [Display(Name = "Customer Name")] public string Name { get; set; } [Display(Name = "e-Mail address")] public string EMail { get; set; } public string Address { get; set; } [Display(Name = "Customer Since")] public DateTime CustomerSince { get; set; } [Display(Name ="Send Newsletter")] public bool SendNewsletter { get; set; } [Display(Name ="Point Balance")] public int? PointBalance { get; set; } } |
This method requires you to have access to the class being displayed in the PropertyGrid control. If you want to change the display strings but are unable to modify the class being used, then you would need to use the C1PropertyGrid.PropertyAttributes property to provide explicit information about each property you want to show on the PropertyGrid.