PropertyGrid > Task-Based Help > 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 C1.WPF.Extended namespace, in the C1.WPF.Extended 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 |
Copy Code
|
---|---|
Public Class Customer Private _Name As String <Display(Name:="Customer Name")> _ Public Property Name() As String Get Return _Name End Get Set(ByVal value As String) _Name = value End Set End Property Private _EMail As String <Display(Name:="e-Mail address")> _ Public Property EMail() As String Get Return _EMail End Get Set(ByVal value As String) _EMail = value End Set End Property Private _Address As String Public Property Address() As String Get Return _Address End Get Set(ByVal value As String) _Address = value End Set End Property Private _CustomerSince As DateTime <Display(Name:="Customer Since")> _ Public Property CustomerSince() As DateTime Get Return _CustomerSince End Get Set(ByVal value As DateTime) _CustomerSince = value End Set End Property Private _SendNewsletter As Boolean <Display(Name:="Send Newsletter")> _ Public Property SendNewsletter() As Boolean Get Return _SendNewsletter End Get Set(ByVal value As Boolean) _SendNewsletter = value End Set End Property Private _PointBalance As System.Nullable(Of Integer) <Display(Name:="Point Balance")> _ Public Property PointBalance() As System.Nullable(Of Integer) Get Return _PointBalance End Get Set(ByVal value As System.Nullable(Of Integer)) _PointBalance = value End Set End Property End Class |
C# |
Copy Code
|
---|---|
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; } } |
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 C1PropertyGrid.PropertyAttributes property to provide explicit information about each property you want to show on the C1PropertyGrid.