Xceed Grid for WinForms v4.3 Documentation
Deriving from the CellEditorManager class
Welcome to Xceed Grid for WinForms v4.3 > Advanced Concepts > Extending the grid's classes > CellEditorManager and CellViewerManager extensions > Deriving from the CellEditorManager class

The CellEditorManager (or child) class can be derived from to use a control to edit the content of a cell. 

The CellEditorManager class exposes a protected virtual "Core" version of most of the public methods (for example, GetFittedWidthCore). When deriving from this class, the "Core" methods can be overridden to add to or replace their existing behavior. The events associated with each method are not raised by the "Core" version of the method but rather by the public "non-Core" version (for example, the corresponding GetFittedWidth method). However, even if the base implementation is not called in the "Core" version, the associated event will still be raised after the "Core" method is called. For example, if the GetFittedWidthCore method of the CellEditorManager class is overridden and the base implementation ignored, the GetFittedWidth method will still be called (by the underlying private implementation) and the QueryFittedWidth event will be raised.

Wrapping a control

When deriving from the CellEditorManager (or child) class to create a custom CellEditorManager, the control used as a template control to edit a cell's content, the property used to retrieve the control's value, as well as other pertinent information must be passed to the base implementation during construction. All the values passed at construction can be accessed (not modified) through the TemplateControl and InPlace properties (see the TrackBarEditor class). 

The CreateControlMode property determines if the same instance of the template control is used to edit the content of cell's or if a new, cloned instance of the template control is used. By default, the CreateControlMode property is set to CreateControlMode.SingleInstance meaning that the same instance of the template control is used to edit the content of the cells. If set to ClonedInstance, a new, cloned instance of the template control will be created and used every time a cell is being edited. In the case where CreateControlMode is set to ClonedInstance, the CreateControl method must be overridden to return a new, cloned instance of the template control. 

To clone a control that does not expose or implement the Clone method, the generic CloneControl method can be used. 

The CellEditorDisplayConditions property indicates under what conditions the CellEditorManager's TemplateControl (or cloned instance of the TemplateControl) is displayed. Combinations of the CellEditorDisplayConditions can be used and specified at the Cell, CellRow, Column, GridControl, and DetailGrid levels. 

The following table provides a list of the possible values for the CelEditorDisplayConditions property: 

Value Description
None A cell's editor is only displayed when the cell is being edited.
MouseOverCell A cell's editor is displayed when the mouse passes over a cell.>

 

MouseOverCell will only function in the case where CreateControlMode is set to ClonedInstance.

MouseOverRow

The cell editors of each cell in a row are displayed when the mouse passes over a row.

MouseOverRow will only function in the case where CreateControlMode is set to ClonedInstance.
RowIsBeingEdited The cell editors of each cell in a row are displayed when one of the cells in the row is being edited.
RowIsCurrent The cell editors of each cell in the CurrentRow are displayed.
CellIsCurrent The editor of the current cell is displayed.
Always The cell editors of each cell in the grid are always displayed. 

Always will only function in the case where CreateControlMode is set to ClonedInstance. 

Setting the CellEditorDisplayConditions property to Always will have a significant negative impact on performance.

The underlying control that is currently displayed by the cell (according to the CellEditorDisplayConditions property), or the control that is currently editing the content of the cell (not the CellEditorManager) can be accessed via the cell's CellEditorControl property. 

The appearance of the underlying control should be defined through the SetControlAppearanceCore method only in the case where the appearance of the control is different depending on the cell. In all other cases, the underlying control's appearance does not need to be determined during the SetControlAppearanceCore method and should instead be determined during the construction of the custom CellEditorManager. 

The ActivateControlCore and DeactivateControlCore methods can be overridden if specific actions are to be taken when the underlying control is activated or deactivated. 

The height and width required by the custom CellEditorManager is determined by the values returned by the GetFittedWidth and GetFittedHeight methods. In order to specify the fitted width and height of the template control, the GetFittedWidthCore and GetFittedHeightCore methods must be overridden and the appropriate values returned. If the values returned by these methods is -1, then the cell's width and height will be used. The bounds of the underlying control can be defined through the CalculateEditorBoundsCore method. 

Through the GetControlValueCore and SetControlValueCore methods, the underlying control's value is, respectively, retrieved and set. If there are no specific particularities in regards to retrieving or setting the underlying control's value, then there is no need to override the GetControlValueCore and/or SetControlValueCore methods. The value will automatically be retrieved and set through the name of the property specified at construction. 

The IsActivationCharCore and IsActivationKeyCore methods can be overridden if the underlying control needs to be activated when certain chars or keys are pressed, while the IsInputCharCore and IsInputKeyCore methods can be overridden if specific chars and/or keys input information into the underlying control.

Validation

Before the underlying control's value is assigned to the cell, it must pass the validation process. The CellEditorManager's Validate method determines if the value passed the validation process and returns true or false depending on the situation. Custom validation can be provided by overriding the ValidateCore method.

Demonstrations

The following classes demonstrates how to derive from the CellEditorManager class to create custom CellEditorManagers: