Skip to main content

Show and Hide Editors

  • 5 minutes to read

Users can edit data in the focused cell. To activate the focused cell’s editor, users can press Enter, F2, or click the cell. The EditorShowMode option specifies how an editor is activated on a mouse click:

  • Default — equivalent to Click if MultiSelectMode is set to CellSelect; otherwise, MouseDown.
  • MouseDown — a cell editor is activated when the left mouse button is pressed.
  • MouseUp — a cell editor is activated when the left mouse button is released. The cell content is selected in this mode. Disable the AutoSelectAllInEditor option to prevent content selection.
  • Click — the first click focuses the cell, the subsequent click activates the editor.
  • MouseDownFocused — a cell editor is activated when the left mouse button is pressed in a cell that is already focused.
  • DoubleClick — a cell editor is activated on a double mouse click.

Note

If the Ctrl, Alt, or Shift key is pressed, the clicked cell is focused, but its editor is not activated.

Show and Hide the Focused Cell’s Editor in Code

Use the following methods to activate and deactivate the focused cell’s editor:

Note

An editor cannot be activated in the following cases:

  • The control’s Editable option is disabled.
  • A column’s AllowEdit option is disabled.
  • A ShowingEditor event handler prohibits the processed cell from being edited by the user.

Active Editor

After an editor is activated, you can use the control’s ActiveEditor property to access it. If there is no active editor in the control, this property returns null (Nothing in VB). To obtain or set the active editor’s value, use the EditingValue property.

The control raises the following events when a user activates an editor:

Focused Cell

Use the following properties to determine the focused cell:

You can also use the editor’s ContainsFocus property to check if the editor is focused. For an editor that can display a pop-up window (for example, a date editor), you can use the EditorContainsFocus property, which returns whether the editor or its pop-up window is focused.

Post the Edited Node to the Data Source

Edits in the focused node are posted to the bound data source only when the node loses focus. Prior to this, edits are stored in cell editors. You can call the following methods to forcibly post the edited node to the data source or discard the changes:

  • EndCurrentEdit() — posts the focused node’s values to the data source. If the New Item Node is focused, the control creates a new node. This method raises the ValidateNode event.
  • CancelCurrentEdit() — discards changes made to the focused node. If the New Item Node is focused, the control does not create a new node.

The code below posts the focused node’s values to the data source each time an editor is hidden.

private void treeList1_HiddenEditor(object sender, EventArgs e) {
    TreeList treeList = sender as TreeList;
    treeList.EndCurrentEdit();
}

Focus and Navigation

Use the OptionsNavigation property to access the following settings that allow you to specify how users can move focus:

  • AutoFocusNewNode — specifies whether a new node is focused.
  • AutoMoveRowFocus — specifies whether the Left/Right Arrow keys move focus to the previous/next node when the current node’s first/last cell is focused.
  • EnterMovesNextColumn — specifies whether the Enter key moves focus between cells.
  • MoveOnEdit — specifies whether the Left Arrow and Right Arrow keys move focus when an editor is active.
  • UseBandsAdvHorzNavigation — specifies whether the Left Arrow and Right Arrow keys move focus with respect to how columns are arranged in bands.
  • UseBandsAdvVertNavigation — specifies whether the Up Arrow and Down Arrow keys move focus with respect to how columns are arranged in bands.
  • UseTabKey — specifies whether the Tab key and the Shift+Tab key combination move focus between cells rather than controls.

Example

The example below handles the following events to change the focused node’s images:

  • TreeList.ShownEditor — sets the node’s state image to indicate that the node is being modified. This event fires when the editor is activated.
  • TreeList.HiddenEditor — removes the node’s state image. This event fires when the editor is deactivated.
  • TreeList.CellValueChanged — sets the node’s select image to indicate that the value has been modified.

cdShowingHidingEditors

using DevExpress.XtraTreeList;

private void treeList1_ShownEditor(object sender, System.EventArgs e) {
   TreeList tlist = sender as TreeList;
   tlist.FocusedNode.StateImageIndex = 0;
}

private void treeList1_HiddenEditor(object sender, System.EventArgs e) {
   TreeList tlist = sender as TreeList;
   tlist.FocusedNode.StateImageIndex = -1;
}

private void treeList1_CellValueChanged(object sender, 
DevExpress.XtraTreeList.CellValueChangedEventArgs e) {
   e.Node.SelectImageIndex = 1;
   e.Node.ImageIndex = 1;
}