In this example, we dynamically generate the PropertyGridControl.PropertyDefinitionsSource and PropertyDefinitionBase.PropertyDefinitionsSource collections based on the underlying data source objects. To generate proper definitions, we implemented a custom PropertyDefinitionTemplateSelector and select one of the following templates based on the underlying property:
1. CollectionDefinitionTemplate. We use it if the underlying property is a collection.
2. CustomDefinitionTemplate. This template is applied only if a specific attribute is set (in this example, we use a custom CustomEditorAttribute).
3. If the underlying object does not meet the previous conditions, we return DefinitionTemplate.
Finally, there is a custom CellTemplateSelector in CustomDefinitionTemplate. In this selector, we check the CustomEditorAttribute attribute value and return one of predefined templates based on it.
↧
PropertyGridControl - How to use various editor types based on custom attribute values
↧