# wx.grid.GridCellEditor¶

This class is responsible for providing and manipulating the in-place edit controls for the grid.

Instances of wx.grid.GridCellEditor (actually, instances of derived classes since it is an abstract class) can be associated with the cell attributes for individual cells, rows, columns, or even for the entire grid.

Normally wx.grid.GridCellEditor shows some UI control allowing the user to edit the cell, but starting with wxWidgets 3.1.4 it’s also possible to define “activatable” cell editors, that change the value of the cell directly when it’s activated (typically by pressing Space key or clicking on it), see TryActivate method. Note that when implementing an editor which is always activatable, i.e. never shows any in-place editor, it is more convenient to derive its class from wx.grid.GridCellActivatableEditor than from wx.grid.GridCellEditor itself.

## Class Hierarchy¶

Inheritance diagram for class GridCellEditor:

## Methods Summary¶

 __init__ Default constructor. ApplyEdit Effectively save the changes in the grid. BeginEdit Fetch the value from the table and prepare the edit control to begin editing. Clone Create a new object which is the copy of this one. Create Creates the actual edit control. Destroy Final cleanup. DoActivate Function which must be overridden for “activatable” editors. EndEdit End editing the cell. GetControl Get the wx.Control used by this editor. GetValue Returns the value currently in the editor control. GetWindow Get the edit window used by this editor. HandleReturn Some types of controls on some platforms may need some help with the Return key. IsAcceptedKey Return True to allow the given key to start editing: the base class version only checks that the event has no modifiers. IsCreated Returns True if the edit control has been created. PaintBackground Draws the part of the cell not occupied by the control: the base class version just fills it with background colour from the attribute. Reset Reset the value in the control back to its starting value. SetControl Set the wx.Control that will be used by this cell editor for editing the value. SetSize Size and position the edit control. SetWindow Set the wx.Window that will be used by this cell editor for editing the value. Show Show or hide the edit control, use the specified attributes to set colours/fonts for it. StartingClick If the editor is enabled by clicking on the cell, this method will be called. StartingKey If the editor is enabled by pressing keys on the grid, this will be called to let the editor do something about that first key if desired. TryActivate Function allowing to create an “activatable” editor. ~wxGridCellEditor The destructor is private because only DecRef can delete us.

## Class API¶

class wx.grid.GridCellEditor(ClientDataContainer, RefCounter)

Possible constructors:

GridCellEditor()


This class is responsible for providing and manipulating the in-place edit controls for the grid.

### Methods¶

__init__(self)

Default constructor.

ApplyEdit(self, row, col, grid)

Effectively save the changes in the grid.

This function should save the value of the control in the grid. It is called only after EndEdit returns True.

Parameters

BeginEdit(self, row, col, grid)

Fetch the value from the table and prepare the edit control to begin editing.

This function should save the original value of the grid cell at the given row and col and show the control allowing the user to change it.

Parameters

Clone(self)

Create a new object which is the copy of this one.

Return type

wx.grid.GridCellEditor

Create(self, parent, id, evtHandler)

Creates the actual edit control.

Parameters

Destroy(self)

Final cleanup.

DoActivate(self, row, col, grid)

Function which must be overridden for “activatable” editors.

If TryActivate is overridden to return “change” action, this function will be called to actually apply this change. Note that it is not passed the value to apply, as it is assumed that the editor class stores this value as a member variable anyhow.

Parameters

New in version 4.1/wxWidgets-3.1.4.

EndEdit(self, row, col, grid, oldval)

End editing the cell.

This function must check if the current value of the editing cell is valid and different from the original value in its string form. If not then simply return None. If it has changed then this method should save the new value so that ApplyEdit can apply it later and the string representation of the new value should be returned.

Notice that this method shoiuld not modify the grid as the change could still be vetoed.

GetControl(self)

Get the wx.Control used by this editor.

This function is preserved for compatibility, but GetWindow should be preferred in the new code as the associated window doesn’t need to be of a Control-derived class.

Note that if SetWindow had been called with an object not deriving from wx.Control, this method will return None.

Return type

Control

GetValue(self)

Returns the value currently in the editor control.

Return type

string

GetWindow(self)

Get the edit window used by this editor.

Return type

Window

New in version 4.1/wxWidgets-3.1.3.

HandleReturn(self, event)

Some types of controls on some platforms may need some help with the Return key.

Parameters

event (wx.KeyEvent) –

IsAcceptedKey(self, event)

Return True to allow the given key to start editing: the base class version only checks that the event has no modifiers.

If the key is F2 (special), editing will always start and this method will not be called at all (but StartingKey will)

Parameters

event (wx.KeyEvent) –

Return type

bool

IsCreated(self)

Returns True if the edit control has been created.

Return type

bool

PaintBackground(self, dc, rectCell, attr)

Draws the part of the cell not occupied by the control: the base class version just fills it with background colour from the attribute.

Parameters

Reset(self)

Reset the value in the control back to its starting value.

SetControl(self, control)

Set the wx.Control that will be used by this cell editor for editing the value.

This function is preserved for compatibility, but SetWindow should be preferred in the new code, see GetControl .

Parameters

control (wx.Control) –

SetSize(self, rect)

Size and position the edit control.

Parameters

rect (wx.Rect) –

SetWindow(self, window)

Set the wx.Window that will be used by this cell editor for editing the value.

Parameters

window (wx.Window) –

New in version 4.1/wxWidgets-3.1.3.

Show(self, show, attr=None)

Show or hide the edit control, use the specified attributes to set colours/fonts for it.

Parameters

StartingClick(self)

If the editor is enabled by clicking on the cell, this method will be called.

StartingKey(self, event)

If the editor is enabled by pressing keys on the grid, this will be called to let the editor do something about that first key if desired.

Parameters

event (wx.KeyEvent) –

TryActivate(self, row, col, grid, actSource)

Function allowing to create an “activatable” editor.

As explained in this class description, activatable editors don’t show any edit control but change the cell value directly, when it is activated (by any way described by wx.grid.GridActivationSource).

To create such editor, this method must be overridden to return wx.grid.GridActivationResult.DoChange passing it the new value of the cell. If the change is not vetoed by wxEVT_GRID_CELL_CHANGING handler, DoActivate will be called to actually change the value, so it must be overridden as well if TryActivate is overridden.

By default, wx.grid.GridActivationResult.DoEdit is returned, meaning that this is a normal editor, using an edit control for changing the cell value.

Parameters
Return type

wx.grid.GridActivationResult

New in version 4.1/wxWidgets-3.1.4.

~wxGridCellEditor(self)

The destructor is private because only DecRef can delete us.

### Properties¶

Control

Value

Window