TypeConverter Support
In certain cases, RadPropertyGrid is used for displaying and editing properties of custom data type. By default, in such scenarios the control will display the custom type as a string. RadPropertyGrid provides TypeConverter support, meaning that this behavior can be modified by defining a custom TypeConverter. The main methods that are usually utilized when implementing a custom TypeConverter are listed below.
Override the CanConvertFrom method that specifies which type the converter can convert from.
Override the ConvertFrom method that implements the conversion.
Override the CanConvertTo method that specifies which type the converter can convert to.
Override the ConvertTo method that implements the conversion.
More information on implementing a TypeConverter can be found in MSDN: How to: Implement a Type Converter.
Defining the Business Object
Demonstrating the TypeConverter mechanism in the scope of RadPropertyGrid will require an object which has a property of custom data type. This section will cover the process of defining them.
The example will use a Club object which has a Captain property of type Player.
Example 1: Defining the business object
Display a Predefined List of Values for a Property with TypeConverter
As of R1 2017, the TypeConverter mechanism of RadPropertyGrid provides support for a standard set of values that can be picked from a predefined list. This can be done through overriding the GetStandardValuesSupported method.
Example 2: Defining a TypeConverter providing a default set of values
If EditorAttribute is set to a specific property with a set TypeConverter the EditorAttribute is with lower priority - a default set of values will be visualized if the GetStandardValuesSupported is overridden instead of an editor.
Figure 1: TypeConverter providing a default set of values
Culture-aware TypeConverter
In this section, the definition of a culture aware TypeConverter will be demonstrated. The support for it is added as of R1 2017. For this purpose, the Height property of the Player object will be used.
Example 3: Defining a culture aware TypeConverter
Figure 2: Culture-aware TypeConverter