In FlexGrid, edit mode can be invoked at runtime using mouse click or even keyboard. To determine programmatically whether the grid is in edit mode, you can read the value of Editor property. If the grid is in edit mode, the property returns a reference to the control that is being used as editor such as TextBox or ComboBox. However, if the grid is not in edit mode, the property returns null.
To put the grid in edit mode programmatically, you can use the StartEditing method and to finish editing, you can call the FinishEditing method. You can also retain the state of edit mode in grid while navigating through the cells by using the PreserveEditMode property.
In addition, FlexGrid fires various events to facilitate better control on the editing process. Below table lists the sequence of events which are fired by the grid during the editing process.
Event Name | Description |
---|---|
BeforeEdit | The event fires whenever an editable cell is selected. It allows you to prevent the cell from being edited by setting the event's Cancel parameter to true. You can also modify the ComboList property so the appropriate drop-down button gets painted in the cell. Note that the user might not actually start editing after this; he could simply move the selection to a different cell or control. |
StartEdit | The event is similar to BeforeEdit, except the user has actually typed a key or clicked the dropdown button in the cell and really is about to start editing. You can still cancel the editing at this point. Note that the Editor property is still null at this point, because the control hasn't yet determined the type of editor that should be used. You can assign custom editors to the Editor property at this point. |
ChangeEdit | The event is a wrapper of editor.TextChanged event. The event fires when the contents of the editor change. You can use this event to keep track of the current content in editor. |
SetupEditor | The event fires after the editor control has been created and configured to edit the cell, but before it is displayed. You can change the editor properties at this point (for example, set the maximum length or password character to be used in a TextBox editor). You can also attach your own event handlers to the editor. |
ValidateEdit | The event fires when the user is done editing, before the editor value gets copied back into the grid. You can examine the original value by retrieving it from the grid (the event provides the coordinates of the cell). You can examine the new value about to be assigned to the grid through the Editor properties (for example, Editor.Text). If the new value is not valid for the cell, set the Cancel parameter to true and the grid remains in edit mode. If instead of keeping the cell in edit mode you would rather restore the original value and leave edit mode, set Cancel parameter to true and then call the FinishEditing method. |
LeaveEdit | This event fires after the grid control leaves edit mode. You can use this event to approve or deny the new cell content or to change the editor content about to be committed. |
AfterEdit | This event fires after the new value has been applied to the cell and the editor has been deactivated. You can use this event to update anything that depends on the cell value (for example, subtotals or sorting). |
Also, there are few events which are related to keyboard operations and are fired when a key is pressed. They are similar to their counterparts from System.Windows.Forms.Control class apart from the fact that they occur when the grid is in edit mode.
Event | Description |
---|---|
KeyDownEdit | This event fires when grid is in edit mode and a key is pressed. You can use this event to perform an action once or even multiple times while the key is held down such as moving a cursor. |
KeyPressEdit | This event fires when grid is in edit mode and a character key is pressed. You can use this event to perform any operation related to typing such as handling input in the cell editor. |
KeyUpEdit | This event fires when grid is in edit mode and key is released. You can use this event to place a logic that executes after KeypressEdit logic has taken effect. |