Clicking In-place Editors' Buttons in Syncfusion GridDataBoundGrid

Applies to TestComplete 15.20, last modified on January 19, 2022

The in-place editors used by the GridDataBoundGrid control may have embedded buttons that can modify the cell value in a special way, invoke popup editors or custom dialogs, and so on. Examples of these buttons are: push buttons, drop-down buttons, spin buttons and so on. This topic describes how you can simulate clicks on the cell’s embedded buttons in your test scripts.

To “press” the cell editor’s button from your test scripts, you can simulate a mouse click on it using the Click action applied to the grid control. This requires you to know the coordinates of the desired button. It is possible to calculate them using internal properties of the GridDataBoundGrid control.

The GridDataBoundGrid control lets you determine coordinates of buttons within the currently selected cell. To get the coordinates of a button that resides in an arbitrary cell, you should first select this cell. To learn how to do this, see Selecting Cells in Syncfusion GridDataBoundGrid.

After the needed cell in selected, you can get the embedded button’s coordinates using the following statement:

GridObj.CurrentCell.Renderer.Buttons.Item( ButtonIndex ).Bounds

GridObj is the scripting object corresponding to the GridDataBoundGrid control, and ButtonIndex is the zero-based button index within the cell. For example, in a NumericUpDown (spin box) cell, the up button has the index of 0 and the down button - 1.

If the currently selected cell only has the dropdown button, you can determine its coordinates using a simpler notation:

GridObj.CurrentCell.Renderer.DropDownButton.Bounds

Note: In order for TestComplete to have access to the properties mentioned, the .NET Application Support plugin must be installed and enabled.

The example below demonstrates how you can click a cell’s embedded buttons.

Example

View description

JavaScript

function Main ()
{
  var p, Grid, Editor;

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

  // Click the PushButton cell
  ClickCellButton (Grid, 2, 5, 0);

  // Pick a date value from the drop-down MonthCalendar editor
  ClickCellDropDownButton (Grid, 2, 9);
  Editor = p.WinFormsObject("PopupHost", "", 1).WinFormsObject("GridDropDownContainer", "").WinFormsObject("MonthCalendar", "");
  Editor.SetSelection ("4/17/2007");
}

function ClickCellButton (Grid, RowIndex, ColumnId, ButtonIndex)
{
  // Select the cell
  SelectCell (Grid, RowIndex, ColumnId);
  // Get the embedded button's coordinates
  let bounds = Grid.CurrentCell.Renderer.Buttons.Item(ButtonIndex).Bounds;
  // Click the button
  Grid.Click (bounds.X + bounds.Width/2, bounds.Y + bounds.Height/2);
}

function ClickCellDropDownButton (Grid, RowIndex, ColumnId)
{
  // Select cell
  SelectCell (Grid, RowIndex, ColumnId);
  // Check if the cell contains a drop-down button
  if (!strictEqual(Grid.CurrentCell.Renderer.DropDownImp, null))
  {
    // Get the button coordinates
    let bounds = Grid.CurrentCell.Renderer.DropDownButton.Bounds;
    // Click the button
    Grid.Click (bounds.X + bounds.Width/2, bounds.Y + bounds.Height/2);
  }
  else
    Log.Error ("Cell (" + RowIndex + ", " + ColumnId + ") contains no drop-down button.");
}

function SelectCell (Grid, RowIndex, ColumnId)
{
  // Try to navigate to the specified cell
  if (Grid.CurrentCell.MoveTo_3 (RowIndex, GetColIndexById(Grid, ColumnId)))
    // Make the selected cell visible
    Grid.CurrentCell.ScrollInView()
  else
    Log.Error ("Cell (" + RowIndex + ", " + ColumnId + ") could not be selected.");
}

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

JScript

function Main ()
{
  var p, Grid, Editor;

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

  // Click the PushButton cell
  ClickCellButton (Grid, 2, 5, 0);

  // Pick a date value from the drop-down MonthCalendar editor
  ClickCellDropDownButton (Grid, 2, 9);
  Editor = p.WinFormsObject("PopupHost", "", 1).WinFormsObject("GridDropDownContainer", "").WinFormsObject("MonthCalendar", "");
  Editor.SetSelection ("4/17/2007");
}

function ClickCellButton (Grid, RowIndex, ColumnId, ButtonIndex)
{
  // Select the cell
  SelectCell (Grid, RowIndex, ColumnId);
  // Get the embedded button's coordinates
  var bounds = Grid.CurrentCell.Renderer.Buttons.Item(ButtonIndex).Bounds;
  // Click the button
  Grid.Click (bounds.X + bounds.Width/2, bounds.Y + bounds.Height/2);
}

function ClickCellDropDownButton (Grid, RowIndex, ColumnId)
{
  // Select cell
  SelectCell (Grid, RowIndex, ColumnId);
  // Check if the cell contains a drop-down button
  if (Grid.CurrentCell.Renderer.DropDownImp != null)
  {
    // Get the button coordinates
    var bounds = Grid.CurrentCell.Renderer.DropDownButton.Bounds;
    // Click the button
    Grid.Click (bounds.X + bounds.Width/2, bounds.Y + bounds.Height/2);
  }
  else
    Log.Error ("Cell (" + RowIndex + ", " + ColumnId + ") contains no drop-down button.");
}

function SelectCell (Grid, RowIndex, ColumnId)
{
  // Try to navigate to the specified cell
  if (Grid.CurrentCell.MoveTo_3 (RowIndex, GetColIndexById(Grid, ColumnId)))
    // Make the selected cell visible
    Grid.CurrentCell.ScrollInView()
  else
    Log.Error ("Cell (" + RowIndex + ", " + ColumnId + ") could not be selected.");
}

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("GDBGMultiHeader")
  p.WinFormsObject("Form1").Activate()
  Grid = p.WinFormsObject("Form1").WinFormsObject("gridRecordNavigationControl1").WinFormsObject("gridDataBoundGrid1")

  # Click the PushButton cell
  ClickCellButton (Grid, 2, 5, 0)

  # Pick a date value from the drop-down MonthCalendar editor
  ClickCellDropDownButton (Grid, 2, 9)
  Editor = p.WinFormsObject("PopupHost", "", 1).WinFormsObject("GridDropDownContainer", "").WinFormsObject("MonthCalendar", "")
  Editor.SetSelection ("4/17/2007")

def ClickCellButton (Grid, RowIndex, ColumnId, ButtonIndex):
  # Select the cell
  SelectCell (Grid, RowIndex, ColumnId)
  # Get the embedded button's coordinates
  bounds = Grid.CurrentCell.Renderer.Buttons.Item(ButtonIndex).Bounds
  # Click the button
  Grid.Click (bounds.X + bounds.Width/2, bounds.Y + bounds.Height/2) 

def ClickCellDropDownButton (Grid, RowIndex, ColumnId):
  # Select cell
  SelectCell (Grid, RowIndex, ColumnId)
  # Check if the cell contains a drop-down button
  if (Grid.CurrentCell.Renderer.DropDownImp != None):
    # Get the button coordinates
    bounds = Grid.CurrentCell.Renderer.DropDownButton.Bounds
    # Click the button
    Grid.Click (bounds.X + bounds.Width/2, bounds.Y + bounds.Height/2)
  else:
    Log.Error ("Cell (" + RowIndex + ", " + ColumnId + ") contains no drop-down button.")

def SelectCell (Grid, RowIndex, ColumnId):
  # Try to navigate to the specified cell
  if (Grid.CurrentCell.MoveTo_3 (RowIndex, GetColIndexById(Grid, ColumnId))):
    # Make the selected cell visible
    Grid.CurrentCell.ScrollInView()
  else:
    Log.Error ("Cell (" + RowIndex + ", " + ColumnId + ") could not be selected.")

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

VBScript

Sub Main
  Dim p, Grid, Editor

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

  ' Click the PushButton cell
  Call ClickCellButton (Grid, 2, 5, 0)
  
  ' Pick date from the drop-down MonthCalendar editor
  Call ClickCellDropDownButton (Grid, 2, 9)
  Set Editor = p.WinFormsObject("PopupHost", "", 1).WinFormsObject("GridDropDownContainer", "").WinFormsObject("MonthCalendar", "")
  Call Editor.SetSelection ("4/17/2007")
End Sub

Sub ClickCellButton (Grid, RowIndex, ColumnId, ButtonIndex)
  Dim bounds
  ' Select the cell
  Call SelectCell (Grid, RowIndex, ColumnId)
  ' Get the embedded button's coordinates
  Set bounds = Grid.CurrentCell.Renderer.Buttons.Item(ButtonIndex).Bounds
  ' Click the button
  Call Grid.Click (bounds.X + bounds.Width/2, bounds.Y + bounds.Height/2)
End Sub

Sub ClickCellDropDownButton (Grid, RowIndex, ColumnId)
  Dim bounds
  ' Select cell
  Call SelectCell (Grid, RowIndex, ColumnId)
  ' Check if the cell contains a drop-down button
  If Not IsEmpty(Grid.CurrentCell.Renderer.DropDownImp) Then
    ' Get the button coordinates
    Set bounds = Grid.CurrentCell.Renderer.DropDownButton.Bounds
    ' Click the button
    Call Grid.Click (bounds.X + bounds.Width/2, bounds.Y + bounds.Height/2)
  Else
    Call Log.Error ("Cell (" & RowIndex & ", " & ColumnId & ") contains no drop-down button.")
  End If
End Sub

Sub SelectCell (Grid, RowIndex, ColumnId)
  ' Try to navigate to the specified cell
  If Grid.CurrentCell.MoveTo_3 (RowIndex, GetColIndexById(Grid, ColumnId)) Then
    ' Make the selected cell visible
    Grid.CurrentCell.ScrollInView
  Else
    Call Log.Error ("Cell (" & RowIndex & ", " & ColumnId & ") could not be selected.")
  End If
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 ClickCellButton (Grid, RowIndex, ColumnId, ButtonIndex); forward;
procedure ClickCellDropDownButton (Grid, RowIndex, ColumnId); forward;
procedure SelectCell (Grid, RowIndex, ColumnId); forward;
function GetColIndexById (Grid, ColumnId); forward;

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

  // Click the PushButton cell
  ClickCellButton (Grid, 2, 5, 0);
  
  // Pick date from the drop-down MonthCalendar editor
  ClickCellDropDownButton (Grid, 2, 9);
  Editor := p.WinFormsObject('PopupHost', '', 1).WinFormsObject('GridDropDownContainer', '').WinFormsObject('MonthCalendar', '');
  Editor.SetSelection ('4/17/2007');
end;

procedure ClickCellButton (Grid, RowIndex, ColumnId, ButtonIndex);
var bounds : OleVariant;
begin
  // Select the cell
  SelectCell (Grid, RowIndex, ColumnId);
  // Get the embedded button's coordinates
  bounds := Grid.CurrentCell.Renderer.Buttons.Item[ButtonIndex].Bounds;
  // Click the button
  Grid.Click (bounds.X + bounds.Width/2, bounds.Y + bounds.Height/2);
end;

procedure ClickCellDropDownButton (Grid, RowIndex, ColumnId);
var bounds : OleVariant;
begin
  // Select cell
  SelectCell (Grid, RowIndex, ColumnId);
  // Check if the cell contains a drop-down button
  if Grid.CurrentCell.Renderer.DropDownImp <> nil then
  begin
    // Get the button coordinates
    bounds := Grid.CurrentCell.Renderer.DropDownButton.Bounds;
    // Click the button
    Grid.Click (bounds.X + bounds.Width/2, bounds.Y + bounds.Height/2);
  end
  else
    Log.Error ('Cell (' + aqConvert.VarToStr(RowIndex) + ', ' + aqConvert.VarToStr(ColumnId) + ') contains no drop-down button.');
end;

procedure SelectCell (Grid, RowIndex, ColumnId);
begin
  // Try to navigate to the specified cell
  if Grid.CurrentCell.MoveTo_3 (RowIndex, GetColIndexById(Grid, ColumnId)) then
    // Make the selected cell visible
    Grid.CurrentCell.ScrollInView
  else
    Log.Error ('Cell (' + aqConvert.VarToStr(RowIndex) + ', ' + aqConvert.VarToStr(ColumnId) + ') could not be selected.');
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, Editor;

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

  // Click the PushButton cell
  ClickCellButton (Grid, 2, 5, 0);

  // Pick a date value from the drop-down MonthCalendar editor
  ClickCellDropDownButton (Grid, 2, 9);
  Editor = p["WinFormsObject"]("PopupHost", "", 1)["WinFormsObject"]("GridDropDownContainer", "")["WinFormsObject"]("MonthCalendar", "");
  Editor["SetSelection"]("4/17/2007");
}

function ClickCellButton (Grid, RowIndex, ColumnId, ButtonIndex)
{
  // Select the cell
  SelectCell (Grid, RowIndex, ColumnId);
  // Get the embedded button's coordinates
  var bounds = Grid["CurrentCell"]["Renderer"]["Buttons"]["Item"](ButtonIndex)["Bounds"];
  // Click the button
  Grid["Click"](bounds["X"] + bounds["Width"]/2, bounds["Y"] + bounds["Height"]/2);
}

function ClickCellDropDownButton (Grid, RowIndex, ColumnId)
{
  // Select cell
  SelectCell (Grid, RowIndex, ColumnId);
  // Check if the cell contains a drop-down button
  if (Grid["CurrentCell"]["Renderer"]["DropDownImp"] != null)
  {
    // Get the button coordinates
    var bounds = Grid["CurrentCell"]["Renderer"]["DropDownButton"]["Bounds"];
    // Click the button
    Grid["Click"](bounds["X"] + bounds["Width"]/2, bounds["Y"] + bounds["Height"]/2);
  }
  else
    Log["Error"]("Cell (" + RowIndex + ", " + ColumnId + ") contains no drop-down button.");
}

function SelectCell (Grid, RowIndex, ColumnId)
{
  // Try to navigate to the specified cell
  if (Grid["CurrentCell"]["MoveTo_3"](RowIndex, GetColIndexById(Grid, ColumnId)))
    // Make the selected cell visible
    Grid["CurrentCell"]["ScrollInView"]()
  else
    Log["Error"]("Cell (" + RowIndex + ", " + ColumnId + ") could not be selected.");
}

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

See Also

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

Highlight search results