This topic describes the various approaches that you can use to obtain and change values assigned to the UltraGrid cells. Note that before getting or setting the cell value, you need to know which row and column the desired cell resides. To determine the cell position, you may need to search for the record containing the desired cell within the grid (for more information, see Searching for Records in Infragistics UltraGrid).
There are two possible ways to obtain and set the values of the cells. The first way is to use the extended wValue
property. The second approach utilizes the native properties of the grid control, it is more complicated, but offers the ability to interact with a cell’s in-place editor.
Obtaining and Setting Cell Values via the wValue
property
Obtaining and Setting Cell Values using native methods and properties
To perform these actions, TestComplete should have access to internal objects, properties and methods of the UltraGrid control. For this purpose, the .NET Application Support plugin must be installed and enabled. When testing Infragistics UltraGrid controls, use specific methods and properties of the corresponding |
Obtaining and Setting Cell Values via the wValue
property
The InfragisticsUltraGrid
and InfragisticsUltraGridView
objects have the wValue
property that provide access to a cell’s value of the main or child data views respectively. This property has parameters that define either the row and column indexes or the row index and column caption.
The property returns the “native” .NET object corresponding to the cell value. Some “simple” values, for example, Integer
, Boolean
and others, are OLE-compatible and thus can be used in scripts directly. Others, such as String
, Decimal
, DateTime
and enumeration values are made OLE-compatible via the OleValue property added to these objects by TestComplete. To work with complex object values, use their internal properties and methods.
Below is an example that demonstrates how you can obtain and set cell values using the wValue
property provided by TestComplete.
Note: | This example works with the SamplesExplorer application that is shipped with the Infragistics NetAdvantage Suite. |
JavaScript
function AccessingExtendedCellValues()
{
var p1, w1, Grid;
// Obtain the application process
p1 = Sys.Process("SamplesExplorer");
// Select the “Per Cell ValueList and Editors” demo
p1.frmMain.WinFormsObject("tvwSamples").DblClickItem("|Feature Samples|V3 Per Cell ValueList and Editors");
w1 = p1.frmCellValueList.WinFormsObject("tabControl1");
// Switch to the “Per Cell Editor” tabbed page
w1.ClickTab("Per Cell Editor");
// Get the grid control
Grid = w1.tabPageCellEditor.panel2.ultraGrid2;
// Obtain a value of an integer cell
Log.Message(Grid.wValue(5, "FieldValue"));
// Assign a new value to cell
Grid.$set("wValue", 5, "FieldValue", 12345);
Log.Message(Grid.wValue(5, "FieldValue"));
// Obtain a value of a text cell
Log.Message(Grid.wValue(0, "FieldValue"));
// Assign a new value to cell
Grid.$set("wValue", 0, "FieldValue", "My Text");
Log.Message(Grid.wValue(0, "FieldValue"));
// Obtain a value of a DateTime cell
Log.Message(Grid.wValue(12, "FieldValue"));
Grid.$set("wValue", 12, "FieldValue", "7/7/2007 3:25:57 PM");
Log.Message(Grid.wValue(12, "FieldValue"));
p1.frmCellValueList.Close();
}
JScript
function AccessingExtendedCellValues()
{
var p1, w1, Grid;
// Obtain the application process
p1 = Sys.Process("SamplesExplorer");
// Select the “Per Cell ValueList and Editors” demo
p1.frmMain.WinFormsObject("tvwSamples").DblClickItem("|Feature Samples|V3 Per Cell ValueList and Editors");
w1 = p1.frmCellValueList.WinFormsObject("tabControl1");
// Switch to the “Per Cell Editor” tabbed page
w1.ClickTab("Per Cell Editor");
// Get the grid control
Grid = w1.tabPageCellEditor.panel2.ultraGrid2;
// Obtain a value of an integer cell
Log.Message(Grid.wValue(5, "FieldValue"));
// Assign a new value to cell
Grid.wValue(5, "FieldValue")= 12345;
Log.Message(Grid.wValue(5, "FieldValue"));
// Obtain a value of a text cell
Log.Message(Grid.wValue(0, "FieldValue"));
// Assign a new value to cell
Grid.wValue(0, "FieldValue")= "My Text";
Log.Message(Grid.wValue(0, "FieldValue"));
// Obtain a value of a DateTime cell
Log.Message(Grid.wValue(12, "FieldValue"));
Grid.wValue(12, "FieldValue")= "7/7/2007 3:25:57 PM";
Log.Message(Grid.wValue(12, "FieldValue"));
p1.frmCellValueList.Close();
}
Python
def AccessingExtendedCellValues():
# Obtain the application process
p1 = Sys.Process("SamplesExplorer")
# Select the "Per Cell ValueList and Editors" demo
p1.frmMain.WinFormsObject("tvwSamples").DblClickItem("|Feature Samples|V3 Per Cell ValueList and Editors")
w1 = p1.frmCellValueList.WinFormsObject("tabControl1")
# Switch to the "Per Cell Editor" tabbed page
w1.ClickTab("Per Cell Editor")
# Get the grid control
Grid = w1.tabPageCellEditor.panel2.ultraGrid2
# Obtain a value of an integer cell
Log.Message(Grid.wValue[5, "FieldValue"])
# Assign a new value to cell
Grid.wValue[5, "FieldValue"]= 12345
Log.Message(Grid.wValue[5, "FieldValue"])
# Obtain a value of a text cell
Log.Message(Grid.wValue[0, "FieldValue"])
# Assign a new value to cell
Grid.wValue[0, "FieldValue"]= "My Text"
Log.Message(Grid.wValue[0, "FieldValue"])
# Obtain a value of a DateTime cell
Log.Message(Grid.wValue[12, "FieldValue"])
Grid.wValue[12, "FieldValue"]= "7/7/2007 3:25:57 PM"
Log.Message(Grid.wValue[12, "FieldValue"])
p1.frmCellValueList.Close()
VBScript
Sub AccessingExtendedCellValues
Dim p1
Dim w1
Dim Grid
' Obtain the application process
Set p1 = Sys.Process("SamplesExplorer")
' Select the “Per Cell ValueList and Editors” demo
Call p1.frmMain.WinFormsObject("tvwSamples").DblClickItem("|Feature Samples|V3 Per Cell ValueList and Editors")
Set w1 = p1.frmCellValueList.WinFormsObject("tabControl1")
' Switch to the “Per Cell Editor” tabbed page
Call w1.ClickTab("Per Cell Editor")
' Get the grid control
Set Grid = w1.tabPageCellEditor.panel2.ultraGrid2
' Obtain a value of an integer cell
Log.Message(Grid.wValue(5, "FieldValue"))
' Assign a new value to cell
Grid.wValue(5, "FieldValue")= 12345
Log.Message(Grid.wValue(5, "FieldValue"))
' Obtain a value of a text cell
Log.Message(Grid.wValue(0, "FieldValue"))
' Assign a new value to cell
Grid.wValue(0, "FieldValue")= "My Text"
Log.Message(Grid.wValue(0, "FieldValue"))
' Obtain a value of a DateTime cell
Log.Message(Grid.wValue(12, "FieldValue"))
Grid.wValue(12, "FieldValue")= "7/7/2007 3:25:57 PM"
Log.Message(Grid.wValue(12, "FieldValue"))
Call p1.frmCellValueList.Close
End Sub
DelphiScript
procedure AccessingExtendedCellValues;
var p1, w1, Grid: OleVariant;
begin
// Obtain the application process
p1 := Sys.Process('SamplesExplorer');
// Select the “Per Cell ValueList and Editors” demo
p1.frmMain.WinFormsObject('tvwSamples').DblClickItem('|Feature Samples|V3 Per Cell ValueList and Editors');
w1 := p1.frmCellValueList.WinFormsObject('tabControl1');
// Switch to the “Per Cell Editor” tabbed page
w1.ClickTab('Per Cell Editor');
// Get the grid control
Grid := w1.tabPageCellEditor.panel2.ultraGrid2;
// Obtain a value of an integer cell
Log.Message(Grid.wValue(5, 'FieldValue'));
// Assign a new value to cell
Grid.wValue(5, 'FieldValue'):= 12345;
Log.Message(Grid.wValue(5, 'FieldValue'));
// Obtain a value of a text cell
Log.Message(Grid.wValue(0, 'FieldValue'));
// Assign a new value to cell
Grid.wValue(0, 'FieldValue') := 'My Text';
Log.Message(Grid.wValue(0, 'FieldValue'));
// Obtain a value of a DateTime cell
Log.Message(Grid.wValue(12, 'FieldValue'));
Grid.wValue(12, 'FieldValue'):= '7/7/2007 3:25:57 PM';
Log.Message(Grid.wValue(12, 'FieldValue'));
p1.frmCellValueList.Close;
end;
C++Script, C#Script
function AccessingExtendedCellValues()
{
var p1, w1, Grid;
// Obtain the application process
p1 = Sys["Process"]("SamplesExplorer");
// Select the “Per Cell ValueList and Editors” demo
p1["frmMain"]["WinFormsObject"]("tvwSamples")["DblClickItem"]("|Feature Samples|V3 Per Cell ValueList and Editors");
w1 = p1["frmCellValueList"]["WinFormsObject"]("tabControl1");
// Switch to the “Per Cell Editor” tabbed page
w1["ClickTab"]("Per Cell Editor");
// Get the grid control
Grid = w1["tabPageCellEditor"]["panel2"]["ultraGrid2"];
// Obtain a value of an integer cell
Log["Message"](Grid["wValue"](5, "FieldValue"));
// Assign a new value to cell
Grid["wValue"](5, "FieldValue")= 12345;
Log["Message"](Grid["wValue"](5, "FieldValue"));
// Obtain a value of a text cell
Log["Message"](Grid["wValue"](0, "FieldValue"));
// Assign a new value to cell
Grid["wValue"](0, "FieldValue")= "My Text";
Log["Message"](Grid["wValue"](0, "FieldValue"));
// Obtain a value of a DateTime cell
Log["Message"](Grid["wValue"](12, "FieldValue"));
Grid["wValue"](12, "FieldValue")= "7/7/2007 3:25:57 PM";
Log["Message"](Grid["wValue"](12, "FieldValue"));
p1["frmCellValueList"]["Close"]();
}
Obtaining and Setting Cell Values using native methods and properties
Another approach is to use the members of UltraGridCell
and UltraGridRow
classes that are exposed by the .NET Application Support plugin.
To get the cell’s contents you can read the Value
or Text
properties of a cell or call the GetCellValue
or GetCellText
methods of the parent row. The Value
property and GetCellValue
method return the underlying data object that is represented by a cell. Whereas the Text
property and GetCellText
method returns the formatted text displayed in a cell. If the cell is in the edit mode the Text
returns the current text that the user has entered into the cell, while the GetCellText
still returns the formatted cell value.
There are different types of UltraGrid cells: text boxes, radio buttons, check boxes, combo boxes, buttons, images, links as well as custom types. The way you interact with cells and modify their values depends on the cell column type. You can read about the ways to assign a new value using some popular in-place editors in the Working With Specific In-place Editors in Infragistics UltraGrid topic. In any case, it is possible to change the cell value by assigning the desired value to the cell’s Value
property.
Example
JavaScript
function AccessingNativeCellValues()
{
var p1, w1, Grid, CellVal;
// Obtain the application process
p1 = Sys.Process("SamplesExplorer");
// Select the "Per Cell ValueList and Editors" demo
p1.frmMain.WinFormsObject("tvwSamples").DblClickItem("|Feature Samples|V3 Per Cell ValueList and Editors");
w1 = p1.frmCellValueList.WinFormsObject("tabControl1");
// Switch to the "Per Cell Editor" tabbed page
w1.ClickTab("Per Cell Editor");
// Get the grid control
Grid = w1.tabPageCellEditor.panel2.ultraGrid2;
// Obtain current cell value
CellVal = GetCellValue(Grid, null, 5, "FieldValue");
Log.Message("The cell's value is: "+CellVal);
// Assign new value to cell
SetCellValue(Grid, null, 5, "FieldValue", "6789");
Log.Message("The cell's value is: "+CellVal);
p1.frmCellValueList.Close();
}
function IsNothingObject(Object)
{
return (strictEqual(Object, null) || equal(aqObject.GetVarType(Object), varNull) || equal(aqObject.GetVarType(Object), varEmpty));
}
function GetCellValue(Grid, View, RowIndex, ColumnID)
{
var Cell, Row, Column;
// 1: Using the UltraGridCell.Value property
Cell = GetCell(Grid, View, RowIndex, ColumnID)
if (!IsNothingObject(Cell))
return Cell.Value.ToString();
else
return "";
// 2: Using the UltraGridCell.Text property
//Cell = GetCell(Grid, View, RowIndex, ColumnID);
//return Cell.Text
// 3: Using the UltraGridRow.GetCellValue method
//Row = GetRow(Grid, View, RowIndex);
//Column = GetColumn(Grid, View, ColumnID);
//return Row.GetCellValue(Column).ToString();
// 4: Using the UltraGridRow.GetCellText method
//Row = GetRow(Grid, View, RowIndex);
//Column = GetColumn(Grid, View, ColumnID);
//return Row.GetCellText(Column);
}
function SetCellValue(Grid, View, RowIndex, ColumnID, NewValue)
{
var Cell;
Cell = GetCell(Grid, View, RowIndex, ColumnID);
Cell.Value = NewValue;
}
JScript
function AccessingNativeCellValues()
{
var p1, w1, Grid, CellVal;
// Obtain the application process
p1 = Sys.Process("SamplesExplorer");
// Select the "Per Cell ValueList and Editors" demo
p1.frmMain.WinFormsObject("tvwSamples").DblClickItem("|Feature Samples|V3 Per Cell ValueList and Editors");
w1 = p1.frmCellValueList.WinFormsObject("tabControl1");
// Switch to the "Per Cell Editor" tabbed page
w1.ClickTab("Per Cell Editor");
// Get the grid control
Grid = w1.tabPageCellEditor.panel2.ultraGrid2;
// Obtain current cell value
CellVal = GetCellValue(Grid, null, 5, "FieldValue");
Log.Message("The cell's value is: "+CellVal);
// Assign new value to cell
SetCellValue(Grid, null, 5, "FieldValue", "6789");
Log.Message("The cell's value is: "+CellVal);
p1.frmCellValueList.Close();
}
function IsNothingObject(Object)
{
return ((Object == null) || (aqObject.GetVarType(Object) == varNull) || (aqObject.GetVarType(Object) == varEmpty));
}
function GetCellValue(Grid, View, RowIndex, ColumnID)
{
var Cell, Row, Column;
// 1: Using the UltraGridCell.Value property
Cell = GetCell(Grid, View, RowIndex, ColumnID)
if (!IsNothingObject(Cell))
return Cell.Value.ToString();
else
return "";
// 2: Using the UltraGridCell.Text property
//Cell = GetCell(Grid, View, RowIndex, ColumnID);
//return Cell.Text
// 3: Using the UltraGridRow.GetCellValue method
//Row = GetRow(Grid, View, RowIndex);
//Column = GetColumn(Grid, View, ColumnID);
//return Row.GetCellValue(Column).ToString();
// 4: Using the UltraGridRow.GetCellText method
//Row = GetRow(Grid, View, RowIndex);
//Column = GetColumn(Grid, View, ColumnID);
//return Row.GetCellText(Column);
}
function SetCellValue(Grid, View, RowIndex, ColumnID, NewValue)
{
var Cell;
Cell = GetCell(Grid, View, RowIndex, ColumnID);
Cell.Value = NewValue;
}
Python
def AccessingNativeCellValues():
# Obtain the application process
p1 = Sys.Process("SamplesExplorer")
# Select the "Per Cell ValueList and Editors" demo
p1.frmMain.WinFormsObject("tvwSamples").DblClickItem("|Feature Samples|V3 Per Cell ValueList and Editors")
w1 = p1.frmCellValueList.WinFormsObject("tabControl1")
# Switch to the "Per Cell Editor" tabbed page
w1.ClickTab("Per Cell Editor")
# Get the grid control
Grid = w1.tabPageCellEditor.panel2.ultraGrid2
# Obtain current cell value
CellVal = GetCellValue(Grid, None, 5, "FieldValue")
Log.Message("The cell's value is: "+CellVal)
# Assign new value to cell
SetCellValue(Grid, None, 5, "FieldValue", "6789")
Log.Message("The cell's value is: "+CellVal)
p1.frmCellValueList.Close()
def IsNothingObject(Object):
return ((Object == None) or (aqObject.GetVarType(Object) == varNone) or (aqObject.GetVarType(Object) == varEmpty))
def GetCellValue(Grid, View, RowIndex, ColumnID):
# 1: Using the UltraGridCell.Value property
Cell = GetCell(Grid, View, RowIndex, ColumnID)
if not IsNothingObject(Cell):
return Cell.Value.ToString()
else:
return ""
# 2: Using the UltraGridCell.Text property
#Cell = GetCell(Grid, View, RowIndex, ColumnID)
#return Cell.Text
# 3: Using the UltraGridRow.GetCellValue method
#Row = GetRow(Grid, View, RowIndex)
#Column = GetColumn(Grid, View, ColumnID)
#return Row.GetCellValue(Column).ToString()
# 4: Using the UltraGridRow.GetCellText method
#Row = GetRow(Grid, View, RowIndex)
#Column = GetColumn(Grid, View, ColumnID)
#return Row.GetCellText(Column)
def SetCellValue(Grid, View, RowIndex, ColumnID, NewValue):
Cell = GetCell(Grid, View, RowIndex, ColumnID)
Cell.Value = NewValue
VBScript
Sub AccessingNativeCellValues
Dim p1, w1, Grid, CellVal
' Obtain the application process
Set p1 = Sys.Process("SamplesExplorer")
' Select the "Per Cell ValueList and Editors" demo
Call p1.frmMain.WinFormsObject("tvwSamples").DblClickItem("|Feature Samples|V3 Per Cell ValueList and Editors")
Set w1 = p1.frmCellValueList.WinFormsObject("tabControl1")
' Switch to the "Per Cell Editor" tabbed page
Call w1.ClickTab("Per Cell Editor")
' Get the grid control
Set Grid = w1.tabPageCellEditor.panel2.ultraGrid2
' Obtain current cell value
CellVal = GetCellValue(Grid, Nothing, 5, "FieldValue")
Log.Message("The cell's value is: "&CellVal)
' Assign new value to cell
Call SetCellValue(Grid, Nothing, 5, "FieldValue", "6789")
Log.Message("The cell's value is: "&CellVal)
Call p1.frmCellValueList.Close
End Sub
Function IsNothingObject (Object)
If aqObject.GetVarType (Object) = varDispatch Then
IsNothingObject = Object Is Nothing
Else
IsNothingObject = IsNull (Object) Or IsEmpty (Object)
End If
End Function
Function GetCellValue(Grid, View, RowIndex, ColumnID)
' 1: Using the UltraGridCell.Value property
Set Cell = GetCell(Grid, View, RowIndex, ColumnID)
If Not IsNothingObject(Cell.Value) Then
GetCellValue = Cell.Value.ToString
Else
GetCellValue = ""
End If
' 2: Using the UltraGridCell.Text property
'Set Cell = GetCell(Grid, View, RowIndex, ColumnID)
'GetCellValue = Cell.Text
' 3: Using the UltraGridRow.GetCellText method
'Set Row = GetRow(Grid, View, RowIndex)
'Set Column = GetColumn(Grid, View, ColumnID)
'GetCellValue = Row.GetCellValue(Column).ToString
' 4: Using the UltraGridRow.GetCellText method
'Set Row = GetRow(Grid, View, RowIndex)
'Set Column = GetColumn(Grid, View, ColumnID)
'GetCellValue = Row.GetCellText(Column)
End Function
Sub SetCellValue(Grid, View, RowIndex, ColumnID, NewValue)
Set Cell = GetCell(Grid, View, RowIndex, ColumnID)
Cell.Value = NewValue
End Sub
DelphiScript
function GetCellValue(Grid, View, RowIndex, ColumnID): Variant; forward;
procedure SetCellValue(grid, View, RowIndex, ColumnID, NewValue); forward;
procedure AccessingNativeCellValues;
var p1, w1, Grid, CellVal: OleVariant;
begin
// Obtain the application process
p1 := Sys.Process('SamplesExplorer');
// Select the "Per Cell ValueList and Editors" demo
p1.frmMain.WinFormsObject('tvwSamples').DblClickItem('|Feature Samples|V3 Per Cell ValueList and Editors');
w1 := p1.frmCellValueList.WinFormsObject('tabControl1');
// Switch to the "Per Cell Editor" tabbed page
w1.ClickTab('Per Cell Editor');
// Get the grid control
Grid := w1.tabPageCellEditor.panel2.ultraGrid2;
// Obtain current cell value
CellVal := GetCellValue(Grid, nil, 5, 'FieldValue');
Log.Message('The cell''s value is: '+CellVal);
// Assign new value to cell
SetCellValue(Grid, nil, 5, 'FieldValue', '6789');
Log.Message('The cell''s value is: '+CellVal);
p1.frmCellValueList.Close;
end;
function GetCellValue(Grid, View, RowIndex, ColumnID): Variant;
var
Cell,Row,Column: Variant;
begin
// 1: Using the UltraGridCell.Value property
Cell := GetCell(Grid, View, RowIndex, ColumnID);
if Cell.Value <> nil then
Result := Cell.Value.ToString
else
Result := '';
// 2: Using the UltraGridCell.Text property
//Cell := GetCell(Grid, View, RowIndex, ColumnID);
//Result := Cell.Text
// 3: Using the UltraGridRow.GetCellValue method
//Row := GetRow(Grid, View, RowIndex);
//Column := GetColumn(Grid, View, ColumnID);
//Result := Row.GetCellValue(Column).ToString;
// 4: Using the UltraGridRow.GetCellText method
//Row := GetRow(Grid, View, RowIndex);
//Column := GetColumn(Grid, View, ColumnID);
//Result := Row.GetCellText(Column);
end;
procedure SetCellValue(grid, View, RowIndex, ColumnID, NewValue);
var
Cell: Variant;
begin
Cell := GetCell(grid, View, RowIndex, ColumnID);
Cell.Value := NewValue;
end;
C++Script, C#Script
function AccessingNativeCellValues()
{
var p1, w1, Grid, CellVal;
// Obtain the application process
p1 = Sys["Process"]("SamplesExplorer");
// Select the "Per Cell ValueList and Editors" demo
p1["frmMain"]["WinFormsObject"]("tvwSamples")["DblClickItem"]("|Feature Samples|V3 Per Cell ValueList and Editors");
w1 = p1["frmCellValueList"]["WinFormsObject"]("tabControl1");
// Switch to the "Per Cell Editor" tabbed page
w1["ClickTab"]("Per Cell Editor");
// Get the grid control
Grid = w1["tabPageCellEditor"]["panel2"]["ultraGrid2"];
// Obtain current cell value
CellVal = GetCellValue(Grid, null, 5, "FieldValue");
Log["Message"]("The cell's value is: "+CellVal);
// Assign new value to cell
SetCellValue(Grid, null, 5, "FieldValue", "6789");
Log["Message"]("The cell's value is: "+CellVal);
p1["frmCellValueList"]["Close"]();
}
function IsNothingObject(Object)
{
return ((Object == null) || (aqObject["GetVarType"](Object) == varNull) || (aqObject["GetVarType"](Object) == varEmpty));
}
function GetCellValue(Grid, View, RowIndex, ColumnID)
{
var Cell, Row, Column;
// 1: Using the UltraGridCell["Value"] property
Cell = GetCell(Grid, View, RowIndex, ColumnID)
if (!IsNothingObject(Cell))
return Cell["Value"]["ToString"]();
else
return "";
// 2: Using the UltraGridCell["Text"] property
//Cell = GetCell(Grid, View, RowIndex, ColumnID);
//return Cell.Text
// 3: Using the UltraGridRow["GetCellValue"] method
//Row = GetRow(Grid, View, RowIndex);
//Column = GetColumn(Grid, View, ColumnID);
//return Row["GetCellValue"](Column)["ToString"]();
// 4: Using the UltraGridRow["GetCellText"] method
//Row = GetRow(Grid, View, RowIndex);
//Column = GetColumn(Grid, View, ColumnID);
//return Row["GetCellText"](Column);
}
function SetCellValue(Grid, View, RowIndex, ColumnID, NewValue)
{
var Cell;
Cell = GetCell(Grid, View, RowIndex, ColumnID);
Cell["Value"] = NewValue;
}
See Also
Working With Infragistics UltraGrid
Accessing Grid Elements in Infragistics UltraGrid
Working With Specific In-place Editors in Infragistics UltraGrid
Copying and Pasting Cell Values in Infragistics UltraGrid
Searching for Records in Infragistics UltraGrid
Selecting Cells in Infragistics UltraGrid
wValue Property (Grid Controls)