Xceed Grid for WinForms v4.3 Documentation
CellEditorManagers

Welcome to Xceed Grid for WinForms v4.3 > Basic Concepts > CellEditorManagers and CellViewerManagers > CellEditorManagers

The CellEditorManager class allows any control to be used as an editor to edit the content of a cells. 

Custom CellEditorManagers can be created by deriving from the CellEditorManager class and implementing the required functionalities, by handling the events that are raised by the CellEditorManager class, or by wrapping a control within an instance of the CellEditorManager class. By default, Xceed Grid for WinForms offers the following predefined CellEditorManager controls: the CheckBoxEditor control which can be used to edit the content of cells which have a boolean datatype, the TextEditor control which can be used to edit the content of cells which have a string datatype, the ComboBoxEditor control which can be used to edit the content of cells which have an ID/Value mapping, the DateEditor control which can be used to edit the content of cells which have a DateTime datatype, and the NumericEditor control which can be used to edit the content of cells which have a numeric datatype. 

The following table provides a list of the available CellEditorManagers as well as the datatype for which they are created by default.

CellEditorManagers Datatype Description
CellEditorManager (none) Allows for any control to be used as an editor to edit the content of a cell.
CheckBoxEditor Boolean Represents an editor that can be used to edit the content of cells which have a boolean datatype.
ComboBoxEditor (none) Represents an editor that can be used to edit the content of cells which have an ID/value mapping.
DateEditor DateTime Represents an editor that can be used to edit the content of cells which have a DateTime datatype.
NumericEditor Numeric Represents an editor that can be used to edit the content of cells which have a numeric datatype.
TextEditor String Represents an editor that can be used to edit the content of cells which have a string datatype.

Using CellEditorManagers

The default CellEditorManagers that are created can be removed or replaced with one of the above mentioned predefined CellEditorManagers or with a custom CellEditorManager by setting the CellEditorManager property of either or a column or a specific cell.

VB.NET Copy Code
GridControl1.Columns( "Phone" ).CellEditorManager = New TextEditor( "( ### ) ###-####" )
C# Copy Code
gridControl1.Columns[ "Phone" ].CellEditorManager = new TextEditor( "( ### ) ###-####" );

Custom CellEditorManagers can be created by deriving from the CellEditorManager class and implementing the required functionalities, by handling the events that are raised by the CellEditorManager class, or by wrapping a control within an instance of the CellEditorManager class. 

The GridControl class exposes the CellEditorManagerMapping property which contain a list of the CellEditorManagers which are created by default for specified datatypes. Values contained in this collection can be modified, added, or removed to change the CellEditorManager which is created by default for all columns of the specified datatype. 

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 CellEditorDisplayConditions 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 current row are displayed.
CellIsCurrent The editor for the current cell is displayed.
Always The cell editors for 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 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.

Wrapping a control in a CellEditorManager

Controls can be wrapped in a CellEditorManager by either deriving from the CellEditorManager class, or by using the constructor that accepts a control as a parameter. This section only deals with wrapping a control through the appropriate constructor. For information on how to derive from the CellEditorManager, refer to the CellViewerManager and CellEditorManager extensions topic 

When wrapping a control in a 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 specified. All the values passed at construction can be accessed (not modified) through the TemplateControl and InPlace properties. 

The appearance of the underlying control can be modified before it is passed to the CellEditorManager, or during the SettingControlAppearance event. If the appearance of the underlying control is the same regardless of the cell's content, then its appearance should be defined directly on the instance of the control. For example:

VB.NET Copy Code
Dim bar As New TrackBar()
Dim manager As New CellEditorManager( bar, "Value", True, True )

' Because these variables affect all instances, there is no need for this to be done
' in the SettingControlAppearance event. If these values were to be applied differently
' depending on a cell value, then they should be done in the SettingControlAppearance event.
bar.Minimum = minValue
bar.Maximum = maxValue
bar.TickStyle = TickStyle.None
bar.AutoSize = False

GridControl1.Columns( "Freight" ).CellEditorManager = manager                       
C# Copy Code
TrackBar bar = new TrackBar();
CellEditorManager manager = new CellEditorManager( bar, "Value", true, true );

// Because these variables affect all instances, there is no need for this to be done
// in the SettingControlAppearance event. If these values were to be applied differently
// depending on a cell value, then they should be done in the SettingControlAppearance event.
bar.Minimum = minValue;
bar.Maximum = maxValue;
bar.TickStyle = TickStyle.None;
bar.AutoSize = false;

gridControl1.Columns[ "Freight" ].CellEditorManager = manager;                       

By default, the value will be retrieved from the underlying control via the property name that was specified when the CellEditorManager was constructed; however, there are some cases where modifications need to be made to the value that is retrieved before it can be assigned to the cell. These modifications can be done via the GettingControlValue event. For example, to continue the above example, we will convert the value retrieved from the underlying control to the value's datatype before it is assigned to the cell using the GettingEditorControlValueEventArgs. CellValue property:

VB.NET Copy Code
AddHandler manager.GettingControlValue, AddressOf Me.manager_GettingControlValue

Private Sub manager_GettingControlValue(ByVal sender As Object, _
                                        ByVal e As GettingEditorControlValueEventArgs)
   ' Return the value of the control that is currently editing the cell
   ' and assign it to the CellValue property.
   e.CellValue = Convert.ChangeType(CType(e.Control, TrackBar).Value, e.ValueDataType)
End Sub                       
C# Copy Code
manager.GettingControlValue += new GettingEditorControlValueEventHandler( manager_GettingControlValue );

private void manager_GettingControlValue( object sender, GettingEditorControlValueEventArgs e )
{
   // Return the value of the control that is currently editing the
   // cell and assign it to the CellValue property.
   e.CellValue = Convert.ChangeType( ( ( TrackBar )e.Control ).Value, e.ValueDataType );
}                       

A complete list of the public properties, methods, and events that are available on the CellEditorManager class is available here.