Skip to main content

Show and Hide Editors

  • 6 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.

Activate an Editor with the Mouse

An editor can be activated when the left mouse button is pressed or released, and may depend on whether the cell is already focused.

When the left mouse button is pressed in a cell for the first time, the cell gets focus. Then the mouse button is released. After the cell is focused, a user can press and release the button again. You can activate a cell editor at each of these four stages depending on usability requirements.

For example, if a control should support drag-and-drop operations, activate an editor when the mouse button is released, not when it is pressed. On the other hand, if an editor’s drop-down window should be opened at the same time a cell is focused, activate the editor when the mouse button is pressed, not when it is released.

Use the EditorShowMode option to specify how a cell editor is activated with the mouse:

  • MouseDown — a cell editor is activated when the left mouse button is pressed regardless of whether the cell is focused.
  • MouseUp — a cell editor is activated when the left mouse button is pressed and released in the same cell regardless of whether the cell is focused.

    The cell content is selected in this mode. Disable the AutoSelectAllInEditor option to prevent content selection.

  • MouseDownFocused — a cell editor is activated when the left mouse button is pressed in a focused cell.
  • Click — a cell editor is activated when the left mouse button is pressed and released in a focused cell.

The Default value is equivalent to the MouseDown value except if users can select multiple cells. That is, the MultiSelectMode option is set to CellSelect. In this case, the Default value is equivalent to the Click value.

In MouseDown and MouseDownFocused modes, the editor is activated when the mouse button is pressed and this mouse event is passed to the activated editor. For example, in an ImageComboBoxEdit, this causes the drop-down window to open. On the other hand, the user cannot drag the row.

In MouseUp and Click modes, the editor is not activated when the mouse button is pressed. This results in this mouse event not being passed to the editor. For example, in an ImageComboBoxEdit, this causes the drop-down window to not open. The user should click the editor one more time to open the drop-down window. On the other hand, the user can drag the row.

Note

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

Disable Editors

Use the following properties to specify whether users can edit cells:

  • The control’s Editable option - specifies whether users can activate editors and edit values. Use the OptionsBehavior property to access this option.
  • A row’s Enabled property - specifies whether users can focus a cell in the row and activate an editor. The row’s caption is grayed-out if the row is disabled.
  • A row’s AllowEdit property - specifies whether users can activate editors and edit values in the row. Use the row’s Properties option to access this property. Unlike the Enabled property, users can focus cells.
  • A row’s ReadOnly property - specifies whether users can edit values. Unlike the AllowEdit option, users can activate the editor to copy the value to the clipboard.
  • The ShowingEditor event’s Cancel argument - allows you to dynamically specify whether an editor can be activated.

You can use the control’s CanShowEditor property to determine whether the focused cell can be edited.

Example

The code below handles the ShowingEditor event to prohibit modification of records whose Trademark field value is set to ‘BMW’. The GetCellValue method returns the Trademark row’s value in the current record.

private void vGridControl1_ShowingEditor(object sender, System.ComponentModel.CancelEventArgs e) {
   VGridControl vGrid = sender as VGridControl;
   string cellValue = vGrid.GetCellValue(vGrid.Rows["rowTrademark"], vGrid.CurrentRecord).ToString();
   if (cellValue == "BMW")
      e.Cancel = true;
}

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 drop-down window (for example, a date editor), you can use the EditorContainsFocus property, which returns whether the editor or its drop-down window is focused.

Show and Hide the Focused Cell’s Editor in Code

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

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:

Examples

The sample code below handles the HiddenEditor event to navigate to the next record and activate the cell editor in the focused row.

private void vGridControl1_HiddenEditor(object sender, System.EventArgs e) {
   VGridControl vGrid = sender as VGridControl;
   if (vGrid.CurrentRecord == vGrid.RecordCount - 1) 
      vGrid.CurrentRecord = 0;
   else 
      vGrid.CurrentRecord++;
   vGrid.ShowEditor();
}

The code below handles the ShownEditor event to open a MemoExEdit editor’s drop-down window in the Report row and assign the current date to the cell.

private void vGridControl1_ShownEditor(object sender, System.EventArgs e) {
   VGridControl vGrid = sender as VGridControl;
   // Obtain the focused row.
   if (!(vGrid.FocusedRow is EditorRow)) return;
   EditorRow currentRow = vGrid.FocusedRow as EditorRow;
   if (currentRow.Properties.Caption == "Report") {
      // The current date.
      string currDate = DateTime.Today.ToShortDateString();
      vGrid.EditingValue = currDate;
      // Obtain the active editor.
      MemoExEdit editor = vGrid.ActiveEditor as MemoExEdit;
      // Invoke the editor's drop-down window.
      editor.ShowPopup();
   }
}
See Also