TreeGrid Cells Tutorial
8. Custom controls and editing
Defining custom controls in cells, especially for editing
-
Use
OnGetHtmlValue
event to display
the custom control in normal, not editing state.
This event receives cell values and should return the HTML code to be displayed in the cell.
Remember, the OnGetHtmlValue event is called whenever the cell is refreshed, it can be many times, so the handler should be fast and also it must not attach to the cell any temporary objects or properties.
-
Or just use Html type cell and define the HTML code directly in the cell value instead of the event.
-
If the custom control does not require any special HTML for display, use standard TreeGrid cell with formatted value.
-
To
edit
the cell value in custom control define OnCustomStartEdit and OnCustomEndEdit.
-
In
OnCustomStartEdit
create the custom control object, display it in grid, focus it and return it back from the handler.
The event receives tag inside that the control should be displayed.
The control can be displayed directly in the tag as its child, or above it in absolute position.
If the handler returns null, the standard editing action will be done.
-
The control should override and cancel key events that it don't want to propagate to TreeGrid key handlers.
In edit mode TreeGrid handles onkeypress for Enter (13) and onkeydown for Esc (27), arrow Up (38), arrow Down (40), Tab (9) and Shift + Tab.
-
If the control requests to finish editing, it should call Grid.EndEdit(1) to save the changes and Grid.EndEdit(0) to discard the changes.
The EndEdit calls OnCustomEndEdit handler, so the control should never modify the cell value directly when finishing edit.
-
In
OnCustomEndEdit
read the edited value from the control, destroy the control and return the value from the handler.
This event receives the custom control object returned by OnCustomStartEdit.