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 internal objects, properties and methods of the XtraGrid control. For this purpose, the .NET Application Support and Developer Express Control Support plugins must be installed and enabled. The latter lets you work with the XtraGrid control using methods and properties of the DevExpressXtraGrid object. Without this plugin, you will not be able to work with XtraGrid controls using their internal methods and properties. |
When testing Developer Express XtraGrid controls, use specific methods and properties of the corresponding DevExpressXtraGrid
object. You can call these methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with an object’s properties and methods from your scripts. However, when testing an XtraGrid control from your keyword test, you can use the same methods and properties calling them from keyword test operations. For more information, see Keyword Tests Basic Operations.
Activating In-place Editors
Depending on the cell’s column settings, you can activate the focused cell’s in-place editor in the following ways:
- By clicking the focused cell. To simulate cell clicks, you can use the
ClickCell
action of aDevExpressXtraGrid
object that corresponds to the XtraGrid control or aDevExpressXtraGridView
object that corresponds to the grid’s child view. - By pressing the F2 key. To send keystrokes to the grid control, use the
Keys
action. - 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.
Note: | 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 ActivateCellEditor
routine demonstrates how to implement some of the described approaches. Its Grid parameter specifies the tested XtraGrid control.
JavaScript, JScript
function ActivateCellEditor (Grid)
{
// Use any of the following statements --
// Simulate the F2 shortcut
Grid.Keys ("[F2]");
// Call the view's ShowEditor method
// Grid.FocusedView.ShowEditor();
}
Python
def ActivateCellEditor (Grid):
# Use any of the following statements --
# Simulate the F2 shortcut
Grid.Keys ("[F2]")
# Call the view's ShowEditor method
# Grid.FocusedView.ShowEditor()
VBScript
Sub ActivateCellEditor (Grid)
' Use any of the following statements --
' Simulate the F2 shortcut
Call Grid.Keys ("[F2]")
' Call the view's ShowEditor method
' Call Grid.FocusedView.ShowEditor
End Sub
DelphiScript
procedure ActivateCellEditor (Grid);
begin
// Use any of the following statements --
// Simulate the F2 shortcut
Grid.Keys ('[F2]');
// Call the view's ShowEditor method
// Grid.FocusedView.ShowEditor;
end;
C++Script, C#Script
function ActivateCellEditor (Grid)
{
// Use any of the following statements --
// Simulate the F2 shortcut
Grid["Keys"]("[F2]");
// Call the view's ShowEditor method
// Grid["FocusedView"]["ShowEditor"]();
}
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.
JavaScript, JScript
function CloseCellEditor (Grid)
{
// Use any of the following statements --
// Simulate the Enter shortcut
Grid.Keys ("[Enter]");
// Call the view's CloseEditor method
// Grid.FocusedView.CloseEditor();
}
Python
def CloseCellEditor (Grid):
# Use any of the following statements --
# Simulate the Enter shortcut
Grid.Keys ("[Enter]")
# Call the view's CloseEditor method
# Grid.FocusedView.CloseEditor()
VBScript
Sub CloseCellEditor (Grid)
' Use any of the following statements --
' Simulate the Enter shortcut
Call Grid.Keys ("[Enter]")
' Call the view's CloseEditor method
' Call Grid.FocusedView.CloseEditor
End Sub
DelphiScript
procedure CloseCellEditor (Grid);
begin
// Use any of the following statements --
// Simulate the Enter shortcut
Grid.Keys ('[Enter]');
// Call the view's CloseEditor method
// Grid.FocusedView.CloseEditor;
end;
C++Script, C#Script
function CloseCellEditor (Grid)
{
// Use any of the following statements --
// Simulate the Enter shortcut
Grid["Keys"]("[Enter]");
// Call the view's CloseEditor method
// Grid["FocusedView"]["CloseEditor"]();
}
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:
JavaScript, JScript
function CancelEditing (Grid)
{
// Use any of the following statements --
// Simulate the Esc keypress
Grid.Keys ("[Esc]");
// Call the view's HideEditor method
// Grid.FocusedView.HideEditor();
}
Python
def CancelEditing (Grid):
# Use any of the following statements --
# Simulate the Esc keypress
Grid.Keys ("[Esc]")
# Call the view's HideEditor method
# Grid.FocusedView.HideEditor()
VBScript
Sub CancelEditing (Grid)
' Use any of the following statements --
' Simulate the Esc keypress
Grid.Keys ("[Esc]")
' Call the view's HideEditor method
' Grid.FocusedView.HideEditor
End Sub
DelphiScript
procedure CancelEditing (Grid);
begin
// Use any of the following statements --
// Simulate the Esc keypress
Grid.Keys ('[Esc]');
// Call the view's HideEditor method
// Grid.FocusedView.HideEditor;
end;
C++Script, C#Script
function CancelEditing (Grid)
{
// Use any of the following statements --
// Simulate the Esc keypress
Grid["Keys"]("[Esc]");
// Call the view's HideEditor method
// Grid["FocusedView"]["HideEditor"]();
}
See Also
Working With Developer Express XtraGrid
Working With Specific In-place Editors in Developer Express XtraGrid
Obtaining and Setting Cell Values in Developer Express XtraGrid
Selecting Cells in Developer Express XtraGrid