Creating Custom Editors

If the built-in editors do not fit your needs, you can easily create your own editors and use them with the C1PropertyGrid.

The following simple steps are required:

1.   Create a class that implements the ITypeEditorControl interface.

2.   Add an instance of this class to the AvailableEditors collection on the C1PropertyGrid control.

OR

Specify this class as the editor for a specific property by adding an EditorAttribute to the property definition.

The ITypeEditorControl interface contains the following members:

      bool Supports(PropertyAttribute Property)
This method is used by the C1PropertyGrid to determine whether the editor supports the type of a given property.

      void Attach(PropertyAttribute property)
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(PropertyAttribute property)
This method is called when the editor instance is being released.

      ITypeEditorControl Create()
This method is called when the C1PropertyGrid needs a new instance of the editor.

      event PropertyChangedEventHandler ValueChanged
This event fires when the value of the property changes. This is used by editors that perform validation.

For a complete implementation of a custom editor, please refer to the ControlExplorer samples installed with ComponentOne Studio for WPF.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.