Copying and Pasting Cell Values in Infragistics UltraWebGrid

Applies to TestComplete 15.10, last modified on December 15, 2021

When testing an application containing Infragistics UltraWebGrid, you may need to copy or paste grid data to and from the clipboard. For example, you can do this to specify the same values in multiple cells or organize a data exchange between the tested application and another one. With TestComplete, you can access the clipboard contents directly using the Sys.Clipboard property. This way, you can get the text copied to the clipboard as well as set the clipboard contents in order to paste them to the application under test.

When testing UltraWebGrid controls, use specific methods and properties of the corresponding InfragisticsWebDataGrid object. In order for TestComplete to be able to access this object, the Infragistics Control Support plugins must be installed and enabled. You can call object methods and properties from your keyword tests, as well as from scripts. This topic describes how to work with object properties and methods from your scripts. However, when testing a GridGroupingControl 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.

You can copy a cell's value to the clipboard or paste it from the clipboard by using the Ctrl+C and Ctrl+V keyboard shortcuts. You can simulate pressing these shortcuts by using the Keys action applied to cells’ in-place editors.

Before performing a copy or paste operation, you need to locate the needed cell in the grid, select it and activate its in-place editor. After the cell’s edit mode is activated, you need to specify the cell contents to be copied or replaced. For example, to select the entire cell value, you can simulate successive Home and Shift+End keystrokes (Home moves the caret to the beginning of the cell text, and Shift+End selects the cell text starting from the caret position to the end). To be able to paste the clipboard contents to a cell, you need to clear the cell’s value, for example, by simulating the Del keystroke after selecting the cell contents. After performing the pasting operation, you need to apply the changes by simulating the Enter keystroke.

Note: The grid control may be configured so that it selects the cell contents right after the cell gets selected. In this case, you do not need to perform any actions to select the cell text to be copied or replaced.

The following example works with the Cell Editors sample application which is part of the Infragistics NetAdvantage 2009 trial download package.

This example illustrates how you can copy an UltraWebGrid cell’s value and paste it to another cell. Note that to select cells and activate their in-place editors, you can call the DblClickCell action of the InfragisticsWebDataGrid object, but to copy and paste data into cells, you need to send keystrokes to the in-place editors.

JavaScript, JScript

function Main ()
{

  var url = "http://my-web-site/web-page-with-ultrawebgrid-2009.aspx";
  Browsers.Item(btIExplorer).Run(url);
  var page = Sys.Browser("*").Page("*");

  // Obtain the frame
  frame = page.Frame("contentBodyIFrame").Frame("main").Form("Form1").Table("igtabUltraWebTab1").Cell(1, 0).Frame("UltraWebTab1_frame0");

  // Obtain the grid object
  grid = frame.Form("ctl00").Table("Table1").Cell(0, 0).Table("UltraWebGrid1_main");

  // Obtain the in-place editors of the two cells
  textbox1 = grid.Cell(1, 0).Panel("UltraWebGrid1_div").Table("G_UltraWebGrid1").Cell(3, 2).TextNode(0);
  textbox2 = grid.Cell(1, 0).Panel("UltraWebGrid1_div").Table("G_UltraWebGrid1").Cell(4, 2).TextNode(0);

  // Select the cell and activate its in-place editor
  grid.DblClickCell(3, "Double");
  // Copy the cell contents to the clipboard
  textbox1.Keys ("^c");

  // Select the other cell and activate its in-place editor
  grid.DblClickCell(4, "Double");
  // Paste the value from the clipboard to the cell
  textbox2.Keys ("^v");
  textbox2.Keys ("[Enter]");
}

Python

def Main ():

  url = "http://my-web-site/web-page-with-ultrawebgrid-2009.aspx"
  Browsers.Item[btIExplorer].Run(url)
  page = Sys.Browser("*").Page("*")

  # Obtain the frame
  frame = page.Frame("contentBodyIFrame").Frame("main").Form("Form1").Table("igtabUltraWebTab1").Cell(1, 0).Frame("UltraWebTab1_frame0")

  # Obtain the grid object
  grid = frame.Form("ctl00").Table("Table1").Cell(0, 0).Table("UltraWebGrid1_main")

  # Obtain the in-place editors of the two cells
  textbox1 = grid.Cell(1, 0).Panel("UltraWebGrid1_div").Table("G_UltraWebGrid1").Cell(3, 2).TextNode(0)
  textbox2 = grid.Cell(1, 0).Panel("UltraWebGrid1_div").Table("G_UltraWebGrid1").Cell(4, 2).TextNode(0)

  # Select the cell and activate its in-place editor
  grid.DblClickCell(3, "Double")
  # Copy the cell contents to the clipboard
  textbox1.Keys ("^c")

  # Select the other cell and activate its in-place editor
  grid.DblClickCell(4, "Double")
  # Paste the value from the clipboard to the cell
  textbox2.Keys ("^v")
  textbox2.Keys ("[Enter]")

VBScript

Sub Main
  Dim url, page, frame, grid, textbox1, textbox2

  url = "http://my-web-site/web-page-with-ultrawebgrid-2009.aspx"
  Browsers.Item(btIExplorer).Run url
  Set page = Sys.Browser("*").Page("*")

  ' Obtain the frame
  Set frame = page.Frame("contentBodyIFrame").Frame("main").Form("Form1").Table("igtabUltraWebTab1").Cell(1, 0).Frame("UltraWebTab1_frame0")

  ' Obtain the grid object
  Set grid = frame.Form("ctl00").Table("Table1").Cell(0, 0).Table("UltraWebGrid1_main")

  ' Obtain the in-place editors of the two cells
  Set textbox1 = grid.Cell(1, 0).Panel("UltraWebGrid1_div").Table("G_UltraWebGrid1").Cell(3, 2).TextNode(0)
  Set textbox2 = grid.Cell(1, 0).Panel("UltraWebGrid1_div").Table("G_UltraWebGrid1").Cell(4, 2).TextNode(0)

  ' Select the cell and activate its in-place editor
  Call grid.DblClickCell(3, "Double")
  ' Copy the cell contents to the clipboard
  Call textbox1.Keys ("^c")

  ' Select the other cell and activate its in-place editor
  Call grid.DblClickCell(4, "Double")
  ' Paste the value from the clipboard to the cell
  Call textbox2.Keys ("^v")
  Call textbox2.Keys ("[Enter]")
End Sub

DelphiScript

procedure Main;
var url, page, frame, grid, textbox1, textbox2 : OleVariant;
begin

  url := 'http://my-web-site/web-page-with-ultrawebgrid-2009.aspx';
  Browsers.Item(btIExplorer).Run(url);
  page := Sys.Browser('*').Page('*');

  // Obtain the frame
  frame := page.Frame('contentBodyIFrame').Frame('main').Form('Form1').Table('igtabUltraWebTab1').Cell(1, 0).Frame('UltraWebTab1_frame0');

  // Obtain the grid object
  grid := frame.Form('ctl00').Table('Table1').Cell(0, 0).Table('UltraWebGrid1_main');

  // Obtain the in-place editors of the two cells
  textbox1 := grid.Cell(1, 0).Panel('UltraWebGrid1_div').Table('G_UltraWebGrid1').Cell(3, 2).TextNode(0);
  textbox2 := grid.Cell(1, 0).Panel('UltraWebGrid1_div').Table('G_UltraWebGrid1').Cell(4, 2).TextNode(0);

  // Select the cell and activate its in-place editor
  grid.DblClickCell(3, 'Double');
  // Copy the cell contents to the clipboard
  textbox1.Keys ('^c');

  // Select the other cell and activate its in-place editor
  grid.DblClickCell(4, 'Double');
  // Paste the value from the clipboard to the cell
  textbox2.Keys ('^v');
  textbox2.Keys ('[Enter]');
end;

C++Script, C#Script

function Main ()
{

  var url = "http://my-web-site/web-page-with-ultrawebgrid-2009.aspx";
  Browsers["Item"](btIExplorer)["Run"](url);
  var page = Sys["Browser"]("*")["Page"]("*");

  // Obtain the frame
  frame = page["Frame"]("contentBodyIFrame")["Frame"]("main")["Form"]("Form1")["Table"]("igtabUltraWebTab1")["Cell"](1, 0)["Frame"]("UltraWebTab1_frame0");

  // Obtain the grid object
  grid = frame["Form"]("ctl00")["Table"]("Table1")["Cell"](0, 0)["Table"]("UltraWebGrid1_main");

  // Obtain the in-place editor
  textbox1 = grid["Cell"](1, 0)["Panel"]("UltraWebGrid1_div")["Table"]("G_UltraWebGrid1")["Cell"](3, 2)["TextNode"](0);
  textbox2 = grid["Cell"](1, 0)["Panel"]("UltraWebGrid1_div")["Table"]("G_UltraWebGrid1")["Cell"](4, 2)["TextNode"](0);

  // Select the cell and activate its in-place editor
  grid["DblClickCell"](3, "Double");
  // Copy the cell contents to the clipboard
  textbox1["Keys"] ("^c");

  // Select the other cell and activate its in-place editor
  grid["DblClickCell"](4, "Double");
  // Paste the value from the clipboard to the cell
  textbox2["Keys"] ("^v");
  textbox2["Keys"] ("[Enter]");
}

See Also

Working With Infragistics UltraWebGrid
Selecting Cells in Infragistics UltraWebGrid
Activating and Closing In-place Editors in Infragistics UltraWebGrid
Obtaining and Setting Cell Values in Infragistics UltraWebGrid

Highlight search results