This topic describes the approaches you can use to obtain and change values stored in UltraWebGrid cells. Note that before getting or setting the cell value, you need to know in which row and column the needed cell resides. For example, you can search for the record containing the needed cell within the grid.
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.
|
Obtaining Cell Values
To get the value from a particular grid cell, you can use the wValue
property of the InfragisticsWebDataGrid
or InfragisticsWebDataGridView
object. The property has the Row and Column parameters, which specify the row and column that contain the cell.
The following example works with the UltraWebGrid - Client Side Object Model sample application, which is part of the Infragistics NetAdvantage 2009 trial download package. The example demonstrates how you can get values of cells of the UltraWebGrid nested table via the wValue
property.
JavaScript, JScript
{
// Obtain the grid object
var url = "http://my-web-site/web-page-with-ultrawebgrid-2009.aspx";
Browsers.Item(btIExplorer).Run(url);
var page = Sys.Browser("*").Page("*");
var grid = page.Frame("contentBodyIFrame").Frame("main").Form("Form1").Table("igtabUltraWebTab1").Cell(1, 0).Frame("UltraWebTab1_frame0").Form("ctl00").Table("Table1").Cell(0, 0).Table("Table2").Cell(1, 0).Table("UltraWebGrid1_main");
// Obtain the nested table
var ChildTable = grid.wChildView(0);
// Post values from the first row of the nested table to the log
for (var Col = 0; Col < ChildTable.wColumnCount; Col++)
Log.Message ("Cell (0, " + Col + ") value: " + ChildTable.wValue(0, Col));
}
Python
def Main ():
# Obtain the grid object
url = "http://my-web-site/web-page-with-ultrawebgrid-2009.aspx"
Browsers.Item[btIExplorer].Run(url)
page = Sys.Browser("*").Page("*")
grid = page.Frame("contentBodyIFrame").Frame("main").Form("Form1").Table("igtabUltraWebTab1").Cell(1, 0).Frame("UltraWebTab1_frame0").Form("ctl00").Table("Table1").Cell(0, 0).Table("Table2").Cell(1, 0).Table("UltraWebGrid1_main")
# Obtain the nested table
ChildTable = grid.wChildView[0]
# Post values from the first row of the nested table to the log
for Col in range(0, ChildTable.wColumnCount-1):
Log.Message ("Cell (0, " + Col + ") value: " + ChildTable.wValue[0, Col])
VBScript
Dim url, page, grid, ChildTable
' Obtain the grid object
url = "http://my-web-site/web-page-with-ultrawebgrid-2009.aspx"
Browsers.Item(btIExplorer).Run url
Set page = Sys.Browser("*").Page("*")
Set grid = page.Frame("contentBodyIFrame").Frame("main").Form("Form1").Table("igtabUltraWebTab1").Cell(1, 0).Frame("UltraWebTab1_frame0").Form("ctl00").Table("Table1").Cell(0, 0).Table("Table2").Cell(1, 0).Table("UltraWebGrid1_main")
' Obtain the nested table
Set ChildTable = grid.wChildView(0)
' Post values from the first row of the nested table to the log
For Col = 0 To ChildTable.wColumnCount-1
Log.Message ("Cell (0, " & Col & ") value: " & CStr(ChildTable.wValue(0, Col)))
Next
End Sub
DelphiScript
var url, page, grid, ChildTable : OleVariant;
begin
// Obtain the grid object
url := 'http://my-web-site/web-page-with-ultrawebgrid-2009.aspx';
Browsers.Item(btIExplorer).Run(url);
page := Sys.Browser('*').Page('*');
grid := page.Frame('contentBodyIFrame').Frame('main').Form('Form1').Table('igtabUltraWebTab1').Cell(1, 0).Frame('UltraWebTab1_frame0').Form('ctl00').Table('Table1').Cell(0, 0).Table('Table2').Cell(1, 0).Table('UltraWebGrid1_main');
// Obtain the nested table
ChildTable := grid.wChildView(0);
// Post values from the first row of the nested table to the log
for Col := 0 to ChildTable.wColumnCount-1 do
Log.Message ('Cell (0, ' + aqConvert.VarToStr(Col) + ') value: ' + aqConvert.VarToStr(ChildTable.wValue[0, Col]));
end;
C++Script, C#Script
{
// Obtain the grid object
var url = "http://my-web-site/web-page-with-ultrawebgrid-2009.aspx";
Browsers["Item"](btIExplorer)["Run"](url);
var page = Sys["Browser"]("*")["Page"]("*");
var grid = page["Frame"]("contentBodyIFrame")["Frame"]("main")["Form"]("Form1")["Table"]("igtabUltraWebTab1")["Cell"](1, 0)["Frame"]("UltraWebTab1_frame0")["Form"]("ctl00")["Table"]("Table1")["Cell"](0, 0)["Table"]("Table2")["Cell"](1, 0)["Table"]("UltraWebGrid1_main");
// Obtain the nested table
var ChildTable = grid["wChildView"](0);
// Post values from the first row of the nested table to the log
for (Col = 0; Col < sChildTable["wColumnCount"]; Col++)
Log["Message"]("Cell (0, " + Col + ") value: " + ChildTable["wValue"](0, Col));
}
Setting Cell Values
To assign new values to Ulta WebGrid cells, you can also use the wValue
property of the InfragisticsWebDataGrid
or InfragisticsWebDataGridView
object. This property is read-write, so it can be used to obtain grid cell values as well as to change them.
The example below demonstrates how you can set new values to grid cells by using the wValue
property. Note that the sample code implies that the cells contain boxes to which text can be entered. The approach provided below works well for most types of in-place editors. However, if the UltraWebGrid control in the tested application uses specific in-place editors, you may need to work with them in a custom way. For instance, the grid can contain columns that use the date chooser control to set the date. You should keep this in mind when setting cells’ values. If you are not sure what data format the cell supports, you can record a script and check how TestComplete recognizes it.
JavaScript
function Main ()
{
// Obtain the grid object
let url = "http://my-web-site/web-page-with-ultrawebgrid-2009.aspx";
Browsers.Item(btIExplorer).Run(url);
let page = Sys.Browser("*").Page("*");
let grid = page.Frame("contentBodyIFrame").Frame("main").Form("Form1").Table("igtabUltraWebTab1").Cell(1, 0).Frame("UltraWebTab1_frame0").Form("ctl00").Table("Table1").Cell(0, 0).Table("Table2").Cell(1, 0).Table("UltraWebGrid1_main");
// Obtain the nested table
let ChildTable = grid.wChildView(0);
// Modify the cells' values
ChildTable.$set("wValue", 0, "Customer ID", "ANATR");
ChildTable.$set("wValue", 0, "Ship Address", "Avda. de la Constitucion 2222");
ChildTable.$set("wValue", 0, "Freight", "43.9");
}
JScript
function Main ()
{
// Obtain the grid object
var url = "http://my-web-site/web-page-with-ultrawebgrid-2009.aspx";
Browsers.Item(btIExplorer).Run(url);
var page = Sys.Browser("*").Page("*");
var grid = page.Frame("contentBodyIFrame").Frame("main").Form("Form1").Table("igtabUltraWebTab1").Cell(1, 0).Frame("UltraWebTab1_frame0").Form("ctl00").Table("Table1").Cell(0, 0).Table("Table2").Cell(1, 0).Table("UltraWebGrid1_main");
// Obtain the nested table
var ChildTable = grid.wChildView(0);
// Modify the cells' values
ChildTable.wValue(0, "Customer ID") = "ANATR";
ChildTable.wValue(0, "Ship Address")= "Avda. de la Constitucion 2222";
ChildTable.wValue(0, "Freight") = "43.9";
}
Python
def Main ():
# Obtain the grid object
url = "http://my-web-site/web-page-with-ultrawebgrid-2009.aspx"
Browsers.Item[btIExplorer].Run(url)
page = Sys.Browser("*").Page("*")
grid = page.Frame("contentBodyIFrame").Frame("main").Form("Form1").Table("igtabUltraWebTab1").Cell(1, 0).Frame("UltraWebTab1_frame0").Form("ctl00").Table("Table1").Cell(0, 0).Table("Table2").Cell(1, 0).Table("UltraWebGrid1_main")
# Obtain the nested table
ChildTable = grid.wChildView[0]
# Modify the cells' values
ChildTable.wValue[0, "Customer ID"] = "ANATR"
ChildTable.wValue[0, "Ship Address"]= "Avda. de la Constitucion 2222"
ChildTable.wValue[0, "Freight"] = "43.9"
VBScript
Sub Main
Dim p, page, grid, ChildTable
' Obtain the grid object
url = "http://my-web-site/web-page-with-ultrawebgrid-2009.aspx"
Browsers.Item(btIExplorer).Run url
Set page = Sys.Browser("*").Page("*")
Set grid = page.Frame("contentBodyIFrame").Frame("main").Form("Form1").Table("igtabUltraWebTab1").Cell(1, 0).Frame("UltraWebTab1_frame0").Form("ctl00").Table("Table1").Cell(0, 0).Table("Table2").Cell(1, 0).Table("UltraWebGrid1_main")
' Obtain the nested table
Set ChildTable = grid.wChildView(0)
' Modify the cells’ values
ChildTable.wValue(0, "Customer ID") = "ANATR"
ChildTable.wValue(0, "Ship Address")= "Avda. de la Constitucion 2222"
ChildTable.wValue(0, "Freight") = "43.9"
End Sub
DelphiScript
procedure Main;
var p, page, grid, ChildTable : OleVariant;
begin
// Obtain the grid object
url := 'http://my-web-site/web-page-with-ultrawebgrid-2009.aspx';
Browsers.Item(btIExplorer).Run(url);
page := Sys.Browser('*').Page('*');
grid := page.Frame('contentBodyIFrame').Frame('main').Form('Form1').Table('igtabUltraWebTab1').Cell(1, 0).Frame('UltraWebTab1_frame0').Form('ctl00').Table('Table1').Cell(0, 0).Table('Table2').Cell(1, 0).Table('UltraWebGrid1_main');
// Obtain the nested table
ChildTable := grid.wChildViewp[0];
// Modify the cells' values
ChildTable.wValue(0, 'Customer ID') := 'ANATR';
ChildTable.wValue(0, 'Ship Address') := 'Avda. de la Constitucion 2222';
ChildTable.wValue(0, 'Freight') := '43.9';
end;
C++Script, C#Script
function Main ()
{
// Obtain the grid object
var url = "http://my-web-site/web-page-with-ultrawebgrid-2009.aspx";
Browsers["Item"](btIExplorer)["Run"](url);
var page = Sys["Browser"]("*")["Page"]("*");
var grid = page["Frame"]("contentBodyIFrame")["Frame"]("main")["Form"]("Form1")["Table"]("igtabUltraWebTab1")["Cell"](1, 0)["Frame"]("UltraWebTab1_frame0")["Form"]("ctl00")["Table"]("Table1")["Cell"](0, 0)["Table"]("Table2")["Cell"](1, 0)["Table"]("UltraWebGrid1_main");
// Obtain the nested table
var ChildTable = grid["wChildView"](0);
// Modify the cells' values
ChildTable["wValue"](0, "Customer ID") = "ANATR";
ChildTable["wValue"](0, "Ship Address")= "Avda. de la Constitucion 2222";
ChildTable["wValue"](0, "Freight") = "43.9";
}
See Also
Working With Infragistics UltraWebGrid
wValue Property (Grid Controls)
Selecting Cells in Infragistics UltraWebGrid
Activating and Closing In-place Editors in Infragistics UltraWebGrid
Copying and Pasting Cell Values in Infragistics UltraWebGrid