[]
PropertyGrid provides a variety of built-in editors and also allows you to create custom editors. Let us discuss about these editors in detail in the following sections.
The PropertyGrid control includes several built-in editors. If you do not specify an editor, PropertyGrid displays each member with a default editor. Hence, you can specify editors based on your requirements and also create your own custom editor, if needed. PropertyGrid provides the AvailableEditors property in the C1PropertyGrid class, which provides you a list of all the built-in editors available in the PropertyGrid control.
The following table lists the built-in editors available in PropertyGrid.
Editor | Description |
---|---|
BoolEditor | Default editor used by C1PropertyGrid to edit Boolean values. |
BrushEditor | Default editor used by C1PropertyGrid to edit Brush values. |
ColorPaletteEditor | Default editor used by C1PropertyGrid to edit color palette values. |
EnumEditor | Default editor used by C1PropertyGrid to edit Enum values. |
ImageSourceEditor | Default editor used by C1PropertyGrid to edit image values. |
NumericEditor | Default editor used by C1PropertyGrid to edit numeric values. |
StringEditor | Default editor used by C1PropertyGrid to edit String values. |
UriEditor | Default editor used by C1PropertyGrid to edit Uri values. |
As the built-in editors in PropertyGrid control are unable to support complex objects, these objects are shown in the default editor (StringEditor). Hence, you may want to create a custom editor to show complex objects so that it fits your needs. You can easily create your own editors to use with the PropertyGrid control. To do so, follow these simple steps:
Create a class that implements the IPropertyGridEditor interface.
Add an instance of this class to the AvailableEditors collection on the PropertyGrid control or specify this class as the editor for a specific property by adding an EditorAttribute to the property definition.
The IPropertyGridEditor interface contains the following members:
bool Supports(PropertyInfo property)
This method is used by the C1PropertyGrid to determine whether the editor supports the type of a given property.
void Attach(FrameworkElement editor, PropertyGroup group, Action<FrameworkElement, object> valueChanged)
This method is called when initializing the editor with the property it will manage. This typically consists of initializing the editor content based on the current property value.
void Detach(FrameworkElement editor)
This method is called when the editor instance is being released.
FrameworkElement Create(C1PropertyGrid parent)
This method is called when the C1PropertyGrid needs a new instance of the editor.
To understand how to create your own custom editor programmatically, see the Nested Properties topic.