Activating and Closing In-place Editors in Developer Express XtraGrid

  May 15, 2007

The XtraGrid control lets users change data directly within the grid cells. To modify cell values, you need to perform certain actions with the cell’s in-place editor. This topic describes how you can activate the editor and apply the changes made.

To perform these actions, TestComplete should have access to the internal methods and properties of the XtraGrid control. That is, the .NET Open Applications plug-in must be installed and enabled.

Activating In-place Editors

Depending on the cell’s column settings, you can activate the in-place editor for the focused cell in the following ways:

  • By clicking the focused cell.
  • By pressing the F2 key.
  • By typing into the focused cell. At that, the cell’s value is replaced by the value typed.
  • Using the ShowEditor method of the grid’s view in which the cell resides.
  • Finally, if the cell column’s ShowEditorMode property has any value except “Click”, the cell’s editor is automatically activated when the cell is clicked. In this case, no special actions are needed to put the cell into the edit mode.

The following ActivateInplaceEditor routine demonstrates how to implement some of the described approaches. Its Grid parameter specifies the tested XtraGrid control. If you decide to activate the edit mode by clicking the cell, you will need to include the helper ClickCell routine from the Selecting Cells in Developer Express XtraGrid article into your code.

Closing In-Place Editors

After you have inputted the new cell value, you need to close the editor and save the changes made. You can do this in two ways:

  • By simulating the Enter key press.
  • By using the grid view’s internal CloseEditor method.

The code snippet below contains the CloseCellEditor routine that can be used to finish editing the grid cell value. The Grid parameter of this routine specifies the grid control under which the action is performed.

You may also need to cancel the editing and discard any changes made to the cell value. For this purpose, you can either send the Esc key press to the grid control, or use the grid view’s internal HideEditor method. The CancelEditing routine in the example below demonstrates how to do this:


Below is an example of how to use introduced routines in test scripts. This example works with the GridTutorials sample application that is shipped with the Developer Express XtraGrid Suite. The Main routine selects some grid cells, makes the grid editable, modifies cell values and then either applies or cancels the changes. The ClickCell routine is used to simulate clicks on grid cells. You can find more information on it in Selecting Cells in Developer Express XtraGrid.