Obtaining and Setting Cell Values in Syncfusion GridDataBoundGrid

Applies to TestComplete 14.40, last modified on April 22, 2021

This topic describes the various approaches that you can use to obtain and change values stored in the GridDataBoundGrid cells. Note that before getting or setting the cell value, you need to know in which row and column the desired cell resides. For example, you can search for the record containing the desired cell within the grid. For more information on identifying rows and columns, see Accessing Rows, Columns and Cells in Syncfusion GridDataBoundGrid.

To perform these actions, TestComplete should have access to internal objects, properties and methods of the GridDataBoundGrid control. For this purpose, the .NET Application Support plugin must be installed and enabled.

When testing Syncfusion GridDataBoundGrid controls, use specific methods and properties of the corresponding SyncfusionEssGrid 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 a GridDataBoundGrid 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 stored in a particular grid cell, you can use the following statements:

GridObj.Item(RowIndex, ColIndex).CellValue

GridObj.Item(RowIndex, ColIndex).Text.OleValue

GridObj is the scripting object corresponding to the GridDataBoundGrid control, RowIndex and ColIndex are zero-based absolute indexes of the cell’s row and column. For more information on identifying rows and columns, see Accessing Rows, Columns and Cells in Syncfusion GridDataBoundGrid.

The CellValue property returns the .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. To get OLE-compatible values of String, Decimal, DateTime and enumeration values, you should use the OleValue property added to these objects by TestComplete. To work with complex object values, use their internal properties and methods.

The Text property, in its turn, returns the text representation of the cell value. We use the OleValue property of the returned string to make it OLE-compatible. Note, however, that in certain cases the text representation of the cell value may significantly differ from the actual text displayed in the cell. For example, the GridDataBoundGrid control may display values with a special formatting applied. Also, it may be configured to display date values as “Tuesday, March 19, 2007” instead of “3/19/2007”, currency values as $123,456.78 instead of 123456.78, and so on. Another example is a grid that uses a lookup (foreign key) combo box that stores values of one dataset field, but displays the corresponding values of another field. For example, the column may hold values of the EmployeeID dataset field but, for usability purposes, display values of the EmployeeName field corresponding to the given EmployeeID value. In this case, the cell’s actual value is different from the displayed text.

In the cases described above, you will most likely want to get the actual text displayed in grid cells rather than the cell values. You can do this using the FormattedText property:

GridObj.Item(RowIndex, ColIndex).FormattedText.OleValue

Below is an example that demonstrates how you can get the GridDataBoundGrid cell values and display text.

Example

View description

JavaScript, JScript

function Main ()
{
  var p, Grid;

  // Obtain the application process and the grid object
  p = Sys.Process ("DataBoundSortByDisplayMember");
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1");

  // Post the 1st row's data to the log
  Log.Message ("ProductID: "   + GetCellText (Grid, 1, 1));
  Log.Message ("ProductName: " + GetCellText (Grid, 1, 2));
  Log.Message ("CategoryID: "  + GetCellValue(Grid, 1, 3).ToString().OleValue);
  Log.Message ("Category: "    + GetCellText (Grid, 1, 3));
  Log.Message ("SupplierID: "  + GetCellValue(Grid, 1, 4).ToString().OleValue);
  Log.Message ("Supplier: "    + GetCellText (Grid, 1, 4));
}

function GetCellValue (Grid, RowIndex, ColumnId)
{
  // Convert the column id to its absolute index
  var ColIndex = GetColIndexById (Grid, ColumnId);
  // Get the cell value
  return Grid.Item(RowIndex, ColIndex).CellValue;
}

function GetCellText (Grid, RowIndex, ColumnId)
{
  // Convert the column id to its absolute index
  var ColIndex = GetColIndexById (Grid, ColumnId);
  // Get the cell's display text
  return Grid.Item(RowIndex, ColIndex).FormattedText.OleValue;
}

function GetColIndexById (Grid, ColumnId)
{
  if (aqObject.GetVarType(ColumnId) == varOleStr)
    return Grid.NameToColIndex(ColumnId)
  else
    return ColumnId;
}

Python

def Main ():

  # Obtain the application process and the grid object
  p = Sys.Process ("DataBoundSortByDisplayMember")
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1")

  # Post the 1st row's data to the log
  Log.Message ("ProductID: "   + GetCellText (Grid, 1, 1))
  Log.Message ("ProductName: " + GetCellText (Grid, 1, 2))
  Log.Message ("CategoryID: "  + GetCellValue(Grid, 1, 3).ToString().OleValue)
  Log.Message ("Category: "    + GetCellText (Grid, 1, 3))
  Log.Message ("SupplierID: "  + GetCellValue(Grid, 1, 4).ToString().OleValue)
  Log.Message ("Supplier: "    + GetCellText (Grid, 1, 4))

def GetCellValue (Grid, RowIndex, ColumnId):
  # Convert the column id to its absolute index
  ColIndex = GetColIndexById (Grid, ColumnId)
  # Get the cell value
  return Grid.Item[RowIndex, ColIndex].CellValue

def GetCellText (Grid, RowIndex, ColumnId):
  # Convert the column id to its absolute index
  ColIndex = GetColIndexById (Grid, ColumnId)
  # Get the cell's display text
  return Grid.Item[RowIndex, ColIndex].FormattedText.OleValue

def GetColIndexById (Grid, ColumnId):
  if (aqObject.GetVarType(ColumnId) == varOleStr):
    return Grid.NameToColIndex(ColumnId)
  else:
    return ColumnId

VBScript

Sub Main
  Dim p, Grid

  ' Obtain the application process and the grid object
  Set p = Sys.Process ("DataBoundSortByDisplayMember")
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1")

  ' Post the 1st row's data to the log
  Log.Message ("ProductID: "   & GetCellText (Grid, 1, 1))
  Log.Message ("ProductName: " & GetCellText (Grid, 1, 2))
  Log.Message ("CategoryID: "  & GetCellValue(Grid, 1, 3).ToString.OleValue)
  Log.Message ("Category: "    & GetCellText (Grid, 1, 3))
  Log.Message ("SupplierID: "  & GetCellValue(Grid, 1, 4).ToString.OleValue)
  Log.Message ("Supplier: "    & GetCellText (Grid, 1, 4))
End Sub

Function GetCellValue (Grid, RowIndex, ColumnId)
  Dim ColIndex
  ' Convert the column id to its absolute index
  ColIndex = GetColIndexById (Grid, ColumnId)
  ' Get the cell value
  If aqObject.GetVarType(Grid.Item(RowIndex, ColIndex).CellValue) = varDispatch Then
    Set GetCellValue = Grid.Item(RowIndex, ColIndex).CellValue
  Else
    GetCellValue = Grid.Item(RowIndex, ColIndex).CellValue
  End If
End Function

Function GetCellText (Grid, RowIndex, ColumnId)
  Dim ColIndex
  ' Convert the column id to its absolute index
  ColIndex = GetColIndexById (Grid, ColumnId)
  ' Get the cell's display text
  GetCellText = Grid.Item(RowIndex, ColIndex).FormattedText.OleValue
End Function

Function GetColIndexById (Grid, ColumnId)
  If aqObject.GetVarType(ColumnId) = varOleStr Then
    GetColIndexById = Grid.NameToColIndex(ColumnId)
  Else
    GetColIndexById = ColumnId
  End If
End Function

DelphiScript

function GetCellValue (Grid, RowIndex, ColumnId); forward;
function GetCellText (Grid, RowIndex, ColumnId); forward;
function GetColIndexById (Grid, ColumnId); forward;

procedure Main;
var p, Grid : OleVariant;
begin
  // Obtain the application process and the grid object
  p := Sys.Process('DataBoundSortByDisplayMember');
  Grid := p.WinFormsObject('Form1').WinFormsObject('gridDataBoundGrid1');

  // Post the 1st row's data to the log
  Log.Message ('ProductID: '   + GetCellText (Grid, 1, 1));
  Log.Message ('ProductName: ' + GetCellText (Grid, 1, 2));
  Log.Message ('CategoryID: '  + GetCellValue(Grid, 1, 3).ToString.OleValue);
  Log.Message ('Category: '    + GetCellText (Grid, 1, 3));
  Log.Message ('SupplierID: '  + GetCellValue(Grid, 1, 4).ToString.OleValue);
  Log.Message ('Supplier: '    + GetCellText (Grid, 1, 4));
end;

function GetCellValue (Grid, RowIndex, ColumnId);
var ColIndex : OleVariant;
begin
  // Convert the column id to its absolute index
  ColIndex := GetColIndexById (Grid, ColumnId);
  // Get the cell value
  Result := Grid.Item[RowIndex,ColIndex].CellValue;
end;

function GetCellText (Grid, RowIndex, ColumnId);
var ColIndex : OleVariant;
begin
  // Convert the column id to its absolute index
  ColIndex := GetColIndexById (Grid, ColumnId);
  // Get the cell's display text
  Result := Grid.Item[RowIndex,ColIndex].FormattedText.OleValue;
end;

function GetColIndexById (Grid, ColumnId);
begin
  if aqObject.GetVarType(ColumnId) = varOleStr then
    Result := Grid.NameToColIndex(ColumnId)
  else
    Result := ColumnId;
end;

C++Script, C#Script

function Main ()
{
  var p, Grid;

  // Obtain the application process and the grid object
  p = Sys["Process"]("DataBoundSortByDisplayMember");
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("gridDataBoundGrid1");

  // Post the 1st row's data to the log
  Log["Message"]("ProductID: "   + GetCellText (Grid, 1, 1));
  Log["Message"]("ProductName: " + GetCellText (Grid, 1, 2));
  Log["Message"]("CategoryID: "  + GetCellValue(Grid, 1, 3)["ToString"]()["OleValue"]);
  Log["Message"]("Category: "    + GetCellText (Grid, 1, 3));
  Log["Message"]("SupplierID: "  + GetCellValue(Grid, 1, 4)["ToString"]()["OleValue"]);
  Log["Message"]("Supplier: "    + GetCellText (Grid, 1, 4));
}

function GetCellValue (Grid, RowIndex, ColumnId)
{
  // Convert the column id to its absolute index
  var ColIndex = GetColIndexById (Grid, ColumnId);
  // Get the cell value
  return Grid["Item"](RowIndex, ColIndex)["CellValue"];
}

function GetCellText (Grid, RowIndex, ColumnId)
{
  // Convert the column id to its absolute index
  var ColIndex = GetColIndexById (Grid, ColumnId);
  // Get the cell's display text
  return Grid["Item"](RowIndex, ColIndex)["FormattedText"]["OleValue"];
}

function GetColIndexById (Grid, ColumnId)
{
  if (aqObject["GetVarType"](ColumnId) == varOleStr)
    return Grid["NameToColIndex"](ColumnId)
  else
    return ColumnId;
}

Setting Cell Values

There are two general approaches for modifying GridDataBoundGrid cell values:

  • Simulating the user actions over the grid cell’s in-place editor, for example, “typing” the new value into the cell.
  • Using internal properties and methods of the GridDataBoundGrid control.

Detailed information and script samples for both approaches are provided below. These approaches work well for most types of in-place editors. However, modifying the cell value programmatically using GridDataBoundGrid internal properties and methods does not involve any user interaction with the grid control and thus will not trigger the corresponding events. That is why you may find that simulating user actions over the grid is more suitable to your needs.

Simulating User Input

To modify grid cell values, you can input the new values directly in grid cells. Note that before that, you should locate the row and column in which the cell resides. For example, you can search for the row containing the cell with the desired value. After you have determined the cell position, you should select the desired cell within the grid and activate the cell’s in-place editor. When the cell’s is in the edit mode, you can “type” the desired value into it using the Keys action applied to the grid control.

Below is an example that illustrates how you can do it. It “types” new values into grid cells.

Example

View description

JavaScript, JScript

function Main ()
{
  var p, Grid;

  // Obtain the application process and the grid object
  p = Sys.Process ("DataBoundSortByDisplayMember");
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1");

  // Modify cell values
  InputCellValue (Grid, 1, 2, "Raclette Courdavault");
  InputCellValue (Grid, 1, 3, "Dairy Products");
  InputCellValue (Grid, 1, 4, "Formaggi Fortini s.r.l.");
}

function InputCellValue (Grid, RowIndex, ColumnId, Value)
{
  // Select the cell and activate its in-place editor
  ClickCell (Grid, RowIndex, ColumnId);
  ActivateCellEditor (Grid);
  // Type the new value
  Grid.Keys ("[Home]![End]" + Value);
  // Save the changes
  CloseCellEditor (Grid);
}

function ClickCell (Grid, RowIndex, ColumnId)
{
  var ColIndex, rect;

  // Convert the column's identifier to its absolute index
  ColIndex = GetColIndexById (Grid, ColumnId);
  // Make cell visible
  Grid.ScrollCellInView_3 (RowIndex, ColIndex);
  // Get the cell coordinates
  rect = Grid.RangeInfoToRectangle (Grid.GridCellsRange.Cell(RowIndex, ColIndex));
  Grid.Click (rect.X + rect.Width/2, rect.Y + rect.Height/2);
}

function ActivateCellEditor (Grid)
{
  if (!Grid.CurrentCell.IsEditing)
    Grid.Keys ("[F2]")
}

function CloseCellEditor (Grid)
{
  Grid.Keys ("[Enter]");
}

function GetColIndexById (Grid, ColumnId)
{
  if (aqObject.GetVarType(ColumnId) == varOleStr)
    return Grid.NameToColIndex(ColumnId)
  else
    return ColumnId;
}

Python

def Main ():

  # Obtain the application process and the grid object
  p = Sys.Process ("DataBoundSortByDisplayMember")
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1")

  # Modify cell values
  InputCellValue (Grid, 1, 2, "Raclette Courdavault")
  InputCellValue (Grid, 1, 3, "Dairy Products")
  InputCellValue (Grid, 1, 4, "Formaggi Fortini s.r.l.")

def InputCellValue (Grid, RowIndex, ColumnId, Value):
  # Select the cell and activate its in-place editor
  ClickCell (Grid, RowIndex, ColumnId)
  ActivateCellEditor (Grid)
  # Type the new value
  Grid.Keys ("[Home]![End]" + Value)
  # Save the changes
  CloseCellEditor (Grid)

def ClickCell (Grid, RowIndex, ColumnId):

  # Convert the column's identifier to its absolute index
  ColIndex = GetColIndexById (Grid, ColumnId)
  # Make cell visible
  Grid.ScrollCellInView_3 (RowIndex, ColIndex)
  # Get the cell coordinates
  rect = Grid.RangeInfoToRectangle (Grid.GridCellsRange.Cell(RowIndex, ColIndex))
  Grid.Click (rect.X + rect.Width/2, rect.Y + rect.Height/2)

def ActivateCellEditor (Grid):
  if not Grid.CurrentCell.IsEditing:
    Grid.Keys ("[F2]")

def CloseCellEditor (Grid):
  Grid.Keys ("[Enter]")

def GetColIndexById (Grid, ColumnId):
  if (aqObject.GetVarType(ColumnId) == varOleStr):
    return Grid.NameToColIndex(ColumnId)
  else:
    return ColumnId

VBScript

Sub Main
  Dim p, Grid

  ' Obtain the application process and the grid object
  Set p = Sys.Process ("DataBoundSortByDisplayMember")
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1")

  ' Modify cell values
  Call InputCellValue (Grid, 1, 2, "Raclette Courdavault")
  Call InputCellValue (Grid, 1, 3, "Dairy Products")
  Call InputCellValue (Grid, 1, 4, "Formaggi Fortini s.r.l.")
End Sub

Sub InputCellValue (Grid, RowIndex, ColumnId, Value)
  ' Select the cell and activate its in-place editor
  Call ClickCell (Grid, RowIndex, ColumnId)
  Call ActivateCellEditor (Grid)
  ' Type the new value
  Call Grid.Keys ("[Home]![End]" & Value)
  ' Save the changes
  Call CloseCellEditor (Grid)
End Sub

Sub ClickCell (Grid, RowIndex, ColumnId)
  Dim ColIndex, rect
  ' Convert the column's identifier to its index
  ColIndex = GetColIndexById (Grid, ColumnId)
  ' Make cell visible
  Call Grid.ScrollCellInView_3 (RowIndex, ColIndex)
  ' Get the cell coordinates
  Set rect = Grid.RangeInfoToRectangle (Grid.GridCellsRange.Cell(RowIndex, ColIndex))
  Call Grid.Click (rect.X + rect.Width/2, rect.Y + rect.Height/2)
End Sub

Sub ActivateCellEditor (Grid)
  If Not Grid.CurrentCell.IsEditing Then
    Call Grid.Keys ("[F2]")
  End If
End Sub

Sub CloseCellEditor (Grid)
  Call Grid.Keys ("[Enter]")
End Sub

Function GetColIndexById (Grid, ColumnId)
  If aqObject.GetVarType(ColumnId) = varOleStr Then
    GetColIndexById = Grid.NameToColIndex(ColumnId)
  Else
    GetColIndexById = ColumnId
  End If
End Function

DelphiScript

procedure InputCellValue (Grid, RowIndex, ColumnId, Value); forward;
procedure ClickCell (Grid, RowIndex, ColumnId); forward;
procedure ActivateCellEditor (Grid); forward;
procedure CloseCellEditor (Grid); forward;
function GetColIndexById (Grid, ColumnId); forward;

procedure Main;
var p, Grid : OleVariant;
begin
  // Obtain the application process and the grid object
  p := Sys.Process ('DataBoundSortByDisplayMember');
  Grid := p.WinFormsObject('Form1').WinFormsObject('gridDataBoundGrid1');

  // Modify cell values
  InputCellValue (Grid, 1, 2, 'Raclette Courdavault');
  InputCellValue (Grid, 1, 3, 'Dairy Products');
  InputCellValue (Grid, 1, 4, 'Formaggi Fortini s.r.l.');
end;

procedure InputCellValue (Grid, RowIndex, ColumnId, Value);
begin
  // Select the cell and activate its in-place editor
  ClickCell (Grid, RowIndex, ColumnId);
  ActivateCellEditor (Grid);
  // Type the new value
  Grid.Keys ('[Home]![End]' + Value);
  // Save the changes
  CloseCellEditor (Grid);
end;

procedure ClickCell (Grid, RowIndex, ColumnId);
var ColIndex, rect : OleVariant;
begin
  // Convert the column's identifier to its index
  ColIndex := GetColIndexById (Grid, ColumnId);
  // Make cell visible
  Grid.ScrollCellInView_3 (RowIndex, ColIndex);
  // Get the cell coordinates
  rect := Grid.RangeInfoToRectangle (Grid.GridCellsRange.Cell(RowIndex, ColIndex));
  Grid.Click (rect.X + rect.Width/2, rect.Y + rect.Height/2);
end;

procedure ActivateCellEditor (Grid);
begin
  if not Grid.CurrentCell.IsEditing then
    Grid.Keys ('[F2]');
end;

procedure CloseCellEditor (Grid);
begin
  Grid.Keys ('[Enter]');
end;

function GetColIndexById (Grid, ColumnId);
begin
  if aqObject.GetVarType(ColumnId) = varOleStr then
    Result := Grid.NameToColIndex(ColumnId)
  else
    Result := ColumnId;
end;

C++Script, C#Script

function Main ()
{
  var p, Grid;

  // Obtain the application process and the grid object
  p = Sys["Process"]("DataBoundSortByDisplayMember");
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("gridDataBoundGrid1");

  // Modify cell values
  InputCellValue (Grid, 1, 2, "Raclette Courdavault");
  InputCellValue (Grid, 1, 3, "Dairy Products");
  InputCellValue (Grid, 1, 4, "Formaggi Fortini s.r.l.");
}

function InputCellValue (Grid, RowIndex, ColumnId, Value)
{
  // Select the cell and activate its in-place editor
  ClickCell (Grid, RowIndex, ColumnId);
  ActivateCellEditor (Grid);
  // Type the new value
  Grid["Keys"]("[Home]![End]" + Value);
  // Save the changes
  CloseCellEditor (Grid);
}

function ClickCell (Grid, RowIndex, ColumnId)
{
  var ColIndex, rect;

  // Convert the column's identifier to its absolute index
  ColIndex = GetColIndexById (Grid, ColumnId);
  // Make cell visible
  Grid["ScrollCellInView_3"](RowIndex, ColIndex);
  // Get the cell coordinates
  rect = Grid["RangeInfoToRectangle"](Grid["GridCellsRange"]["Cell"](RowIndex, ColIndex));
  Grid["Click"](rect["X"] + rect["Width"]/2, rect["Y"] + rect["Height"]/2);
}

function ActivateCellEditor (Grid)
{
  if (! Grid["CurrentCell"]["IsEditing"])
    Grid["Keys"]("[F2]")
}

function CloseCellEditor (Grid)
{
  Grid["Keys"]("[Enter]");
}

function GetColIndexById (Grid, ColumnId)
{
  if (aqObject["GetVarType"](ColumnId) == varOleStr)
    return Grid["NameToColIndex"](ColumnId)
  else
    return ColumnId;
}

The GridDataBoundGrid control may contain cells with embedded buttons (for example, the drop-down button, spin buttons, and so on) that can be used to invoke popup editors or perform specific actions. To learn how you can “press” these buttons from scripts, see Clicking In-place Editors' Buttons in Syncfusion GridDataBoundGrid.

A possible alternative to typing data into the cell is to paste it from the clipboard. For more information on how to do this, see Copying and Pasting Cell Values in Syncfusion GridDataBoundGrid.

Using GridDataBoundGrid Internal Methods

It is possible to set grid cell values using internal properties of the GridDataBoundGrid control. The CellValue, Text and FormattedText properties described in the Obtaining Cell Values section above can be used to get the cell values (displayed text) as well as to modify them. So, you can use the Value property to specify the cell value, the Text property to specify the cell value by its string representation, and the FormattedText property to set the new cell value that corresponds to the specified formatted text.

Note that when using the Value property to modify the cell value of a complex type, such as System.DateTime, System.Drawing.Color and others, you need to create an instance of the corresponding .NET class. For more information on how to do this, see Calling Functions From .NET Assemblies. As an alternative, you can use the Text or FormattedText properties to specify the desired value by its text representation. The specified string will be parsed and converted to the cell value.

Below is an example that demonstrates how you can set grid cell values from scripts.

Example

View description

JavaScript, JScript

function Main ()
{
  var p, Grid;

  // Obtain the application process and the grid object
  p = Sys.Process ("DataBoundSortByDisplayMember");
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1");

  // Modify the cells' values by parsing the specified formatted text
  SetCellText (Grid, 1, 2, "Raclette Courdavault");
  SetCellText (Grid, 1, 3, "Dairy Products");
  SetCellText (Grid, 1, 4, "Formaggi Fortini s.r.l.");

  // Modify the cells' values themselves
  SetCellValue (Grid, 2, 2, "Ravioli Angelo");
  SetCellValue (Grid, 2, 3, 5); // Category_ID value for "Grains/Cereals"
  SetCellValue (Grid, 2, 4, 26); // Supplier_ID value for "Pasta Buttini s.r.l."
}

function SetCellValue (Grid, RowIndex, ColumnId, Value)
{
  // Convert the column id to its absolute index
  var ColIndex = GetColIndexById (Grid, ColumnId);
  // Set the cell value
  Grid.Item(RowIndex, ColIndex).CellValue = Value;
}

function SetCellText (Grid, RowIndex, ColumnId, Text)
{
  // Convert the column id to its absolute index
  var ColIndex = GetColIndexById (Grid, ColumnId);
  // Parse the formatted text into the cell value
  Grid.Item(RowIndex, ColIndex).FormattedText = Text;
}

function GetColIndexById (Grid, ColumnId)
{
  if (aqObject.GetVarType(ColumnId) == varOleStr)
    return Grid.NameToColIndex(ColumnId)
  else
    return ColumnId;
}

Python

def Main ():

  # Obtain the application process and the grid object
  p = Sys.Process ("DataBoundSortByDisplayMember")
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1")

  # Modify the cells' values by parsing the specified formatted text
  SetCellText (Grid, 1, 2, "Raclette Courdavault")
  SetCellText (Grid, 1, 3, "Dairy Products")
  SetCellText (Grid, 1, 4, "Formaggi Fortini s.r.l.")

  # Modify the cells' values themselves
  SetCellValue (Grid, 2, 2, "Ravioli Angelo")
  SetCellValue (Grid, 2, 3, 5) # Category_ID value for "Grains/Cereals"
  SetCellValue (Grid, 2, 4, 26) # Supplier_ID value for "Pasta Buttini s.r.l."

def SetCellValue (Grid, RowIndex, ColumnId, Value):
  # Convert the column id to its absolute index
  ColIndex = GetColIndexById (Grid, ColumnId)
  # Set the cell value
  Grid.Item(RowIndex, ColIndex).CellValue = Value

def SetCellText (Grid, RowIndex, ColumnId, Text):
  # Convert the column id to its absolute index
  ColIndex = GetColIndexById (Grid, ColumnId)
  # Parse the formatted text into the cell value
  Grid.Item[RowIndex, ColIndex].FormattedText = Text

def GetColIndexById (Grid, ColumnId):
  if (aqObject.GetVarType(ColumnId) == varOleStr):
    return Grid.NameToColIndex(ColumnId)
  else:
    return ColumnId

VBScript

Sub Main
  Dim p, Grid

  ' Obtain the application process and the grid object
  Set p = Sys.Process ("DataBoundSortByDisplayMember")
  Set Grid = p.WinFormsObject("Form1").WinFormsObject("gridDataBoundGrid1")

  ' Modify the cells' values by parsing the specified formatted text
  Call SetCellText (Grid, 1, 2, "Raclette Courdavault")
  Call SetCellText (Grid, 1, 3, "Dairy Products")
  Call SetCellText (Grid, 1, 4, "Formaggi Fortini s.r.l.")

  ' Modify the cells' values themselves
  Call SetCellValue (Grid, 2, 2, "Ravioli Angelo")
  Call SetCellValue (Grid, 2, 3, 5) ' Category_ID value for "Grains/Cereals"
  Call SetCellValue (Grid, 2, 4, 26) ' Supplier_ID value for "Pasta Buttini s.r.l."
End Sub

Sub SetCellValue (Grid, RowIndex, ColumnId, Value)
  Dim ColIndex
  ' Convert the column id to its absolute index
  ColIndex = GetColIndexById (Grid, ColumnId)
  ' Set the cell value
  If aqObject.GetVarType (Value) = varDispatch Then
    Set Grid.Item(RowIndex, ColIndex).CellValue = Value
  Else
    Grid.Item(RowIndex, ColIndex).CellValue = Value
  End If
End Sub

Sub SetCellText (Grid, RowIndex, ColumnId, Text)
  Dim ColIndex
  ' Convert the column id to its absolute index
  ColIndex = GetColIndexById (Grid, ColumnId)
  ' Parse the formatted text into the cell value
  Grid.Item(RowIndex, ColIndex).FormattedText = Text
End Sub

Function GetColIndexById (Grid, ColumnId)
  If aqObject.GetVarType(ColumnId) = varOleStr Then
    GetColIndexById = Grid.NameToColIndex(ColumnId)
  Else
    GetColIndexById = ColumnId
  End If
End Function

DelphiScript

procedure SetCellValue (Grid, RowIndex, ColumnId, Value); forward;
procedure SetCellText (Grid, RowIndex, ColumnId, Text); forward;
function GetColIndexById (Grid, ColumnId); forward;

procedure TestSetCellValueText;
var p, Grid : OleVariant;
begin
  // Obtain the application process and the grid object
  p := Sys.Process ('DataBoundSortByDisplayMember');
  Grid := p.WinFormsObject('Form1').WinFormsObject('gridDataBoundGrid1');

  // Modify the cells' values by parsing the specified formatted text
  SetCellText (Grid, 1, 2, 'Raclette Courdavault');
  SetCellText (Grid, 1, 3, 'Dairy Products');
  SetCellText (Grid, 1, 4, 'Formaggi Fortini s.r.l.');

  // Modify the cells' values themselves
  SetCellValue (Grid, 2, 2, 'Ravioli Angelo');
  SetCellValue (Grid, 2, 3, 5); // Category_ID value for "Grains/Cereals"
  SetCellValue (Grid, 2, 4, 26); // Supplier_ID value for "Pasta Buttini s.r.l."
end;

procedure SetCellValue (Grid, RowIndex, ColumnId, Value);
var ColIndex : OleVariant;
begin
  // Convert the column id to its absolute index
  ColIndex := GetColIndexById (Grid, ColumnId);
  // Set the cell value
  Grid.Item(RowIndex, ColIndex).CellValue := Value;
end;

procedure SetCellText (Grid, RowIndex, ColumnId, Text);
var ColIndex : OleVariant;
begin
  // Convert the column id to its absolute index
  ColIndex := GetColIndexById (Grid, ColumnId);
  // Parse the formatted text into the cell value
  Grid.Item(RowIndex, ColIndex).FormattedText := Text;
end;

function GetColIndexById (Grid, ColumnId);
begin
  if aqObject.GetVarType(ColumnId) = varOleStr then
    Result := Grid.NameToColIndex(ColumnId)
  else
    Result := ColumnId;
end;

C++Script, C#Script

function Main ()
{
  var p, Grid;

  // Obtain the application process and the grid object
  p = Sys["Process"]("DataBoundSortByDisplayMember");
  Grid = p["WinFormsObject"]("Form1")["WinFormsObject"]("gridDataBoundGrid1");

  // Modify the cells' values by parsing the specified formatted text
  SetCellText (Grid, 1, 2, "Raclette Courdavault");
  SetCellText (Grid, 1, 3, "Dairy Products");
  SetCellText (Grid, 1, 4, "Formaggi Fortini s.r.l.");

  // Modify the cells' values themselves
  SetCellValue (Grid, 2, 2, "Ravioli Angelo");
  SetCellValue (Grid, 2, 3, 5); // Category_ID value for "Grains/Cereals"
  SetCellValue (Grid, 2, 4, 26); // Supplier_ID value for "Pasta Buttini s.r.l."
}

function SetCellValue (Grid, RowIndex, ColumnId, Value)
{
  // Convert the column id to its absolute index
  var ColIndex = GetColIndexById (Grid, ColumnId);
  // Set the cell value
  Grid["Item"](RowIndex, ColIndex)["CellValue"] = Value;
}

function SetCellText (Grid, RowIndex, ColumnId, Text)
{
  // Convert the column id to its absolute index
  var ColIndex = GetColIndexById (Grid, ColumnId);
  // Parse the formatted text into the cell value
  Grid["Item"](RowIndex, ColIndex)["FormattedText"] = Text;
}

function GetColIndexById (Grid, ColumnId)
{
  if (aqObject["GetVarType"](ColumnId) == varOleStr)
    return Grid["NameToColIndex"](ColumnId)
  else
    return ColumnId;
}

See Also

Working With Syncfusion GridDataBoundGrid
Accessing Rows, Columns and Cells in Syncfusion GridDataBoundGrid
Selecting Cells in Syncfusion GridDataBoundGrid
Activating and Closing In-place Editors in Syncfusion GridDataBoundGrid
Clicking In-place Editors' Buttons in Syncfusion GridDataBoundGrid
Copying and Pasting Cell Values in Syncfusion GridDataBoundGrid

Highlight search results