Working With Drop-Down Editors in Developer Express XtraGrid
The Developer Express XtraGrid control offers a variety of in-place editors that can be used in the grid: combo boxes, check boxes, radio buttons, spin boxes and various drop-down editors. In the Modifying Cell Values in Developer Express XtraGrid article, I have described two general approaches for modifying grid cell values.
However, you may need to modify the cell value in a specific way for the cell editor, for example, simulate actions in the cells dropdown editor. This article describes how you can work with drop-down editors in TestComplete scripts.
Note: The explanation below presumes that TestComplete has access to internal properties, methods and actions of the XtraGrid control, that is, that the .NET Open Applications plug-in is installed and enabled.
When you start editing the grid cell value, that is, after you select the cell and activate the edit mode, the grid creates the corresponding edit control (in-place editor) for this. To access the current editor, use the
ActiveEditor property of the grids view where the cell being edited resides. After the user has finished editing the cell value, the editor object is destroyed. After that, the
ActiveEditor property returns the empty value. Thus, the editor object only exists and can be accessed when it is active. To check if the grid control is in the editing mode, you can use the
IsEditing property of the grids active view.
When the cell is in edit mode, you can invoke its drop-down editor by simulating the
F4 keypress. The same shortcut can be used to close the editor. Alternatively, you show or hide a drop-down editor by using internal methods and properties of the object returned by the
ActiveEditor property. If the editor has a drop-down part, this object provides the following properties and methods:
ShowPopup - Method. Displays the popup window.
ClosePopup - Method. Closes the popup window accepting the changes made.
CancelPopup - Method. Closes the popup window discarding the changes made.
IsPopupOpen - Property. Returns True if the editors popup window is currently displayed, and False if it is hidden.
You can access a popup object using the
PopupForm property of the
ActiveEditor object. However, this property returns the native .NET object corresponding to the popup window, so this object is not wrapped with TestCompletes special methods and properties. To get a wrapped object corresponding to the popup window, use the
Sys.WindowFromHandle method and pass the popup windows handle (the
Handle property value) as a parameter. This will let you use specific methods of wrapped objects (such as
Keys) to simulate the desired user actions over the popup window.
The following eample demonstrates how you can simulate actions over drop-down editors in the XtraGrid control. The example works with the GridTutorials application that is shipped with the Developer Express XtraGrid Suite. The script contains the following routines:
- Main - The main routine. It obtains the scripting object corresponding to the XtraGrid control and modifies values in cells that use the drop-down calendar and calculator editors.
- The OpenDropDownEditor function displays the in-place editors popup window and returns an
onscreen object corresponding to the popup window. The function has the following parameters:
- Grid - The tested XtraGrid control.
- View - The grids view where the cell resides. If this parameter is
Nothing, it is assumed that the cell is situatted in the grids main (top-level) view.
- RowIndex - The zero-based index of the row (card) that contains the cell.
- ColumnId - The caption or the zero-based index of the grid column (card field) to which the cell belongs.
The routine performs the following actions:
- Clicks the specified cell and activates the edit mode,
- Obtains the native editor object
- Checks if the editor object contains the
IsDroppedDown property (if the object does not contain this property, it does not have a drop-down window). To perform the check, we use the
- If the editor has a drop-down window, the routine simulates the F4 shortcut to invoke this drop-down window.
- Then the routine uses the editors
PopupForm property to obtain the scripitng object corresponding to the popup window.
- The CloseDropDownEditor routine hides the popup window of the currently active in-place editor and saves the changes made. The routine code is very similar to the
OpenDropDownEditor function code.
- ActivateCellEditor - Activates the cells edit mode using the
- CloseCellEditor - Simulates the
Enter key press to apply changes made to the cell value.
- ClickCell - Simulates a mouse click on the specified grid cell. The source code of this routine is not included in this script; you can find it in the Selecting Cells in Developer Express XtraGrid article.
TestCompletes help system contains more examples on working with custom in-place editors: check boxes, radio button groups, button edits and others. You can find these examples in the Working With Specific In-place Editors in Developer Express XtraGrid help topic.