Simulating Mouse Clicks Over Column Headers in Borland TDBGrid

Applies to TestComplete 15.69, last modified on November 13, 2024

When testing applications that use TDBGrid controls, you may need to simulate mouse clicks over a column header. For example, in this way you can sort the grid data, if sorting is enabled. This topic explains how you can simulate column header clicks in scripts.

You can simulate a click on a grid column header using the ClickColumnHeader action of the BorlandTDBGrid object. This action uses two parameters: Column, which specifies the grid column to be clicked, and Shift, which specifies whether the Ctrl, Shift or Alt key should be pressed during the click.

The BorlandTDBGrid object is only available in TestComplete if the following conditions are met:

Below is an example that demonstrates how you can use the ClickColumnHeader action in scripts:

JavaScript, JScript

function Main ()
{
  var p, Grid;

  // Obtain the grid object
  p = Sys.Process("csdemos");
  p.VCLObject("FrmLauncher").VCLObject("BtnViews").ClickButton();
  Grid = p.VCLObject("FrmViewDemo").VCLObject("Panel2").VCLObject("DBGrid1");

  // Click on a column header
  Grid.ClickColumnHeader ("FirstName");
}

Python

def Main ():

  # Obtain the grid object
  p = Sys.Process("csdemos")
  p.VCLObject("FrmLauncher").VCLObject("BtnViews").ClickButton()
  Grid = p.VCLObject("FrmViewDemo").VCLObject("Panel2").VCLObject("DBGrid1")

  # Click on a column header
  Grid.ClickColumnHeader ("FirstName")

VBScript

Sub Main
  Dim p, Grid

  ' Obtain the grid object
  Set p = Sys.Process("csdemos")
  p.VCLObject("FrmLauncher").VCLObject("BtnViews").ClickButton
  Set Grid = p.VCLObject("FrmViewDemo").VCLObject("Panel2").VCLObject("DBGrid1")

  ' Click on a column header
  Grid.ClickColumnHeader ("FirstName")
End Sub

DelphiScript

procedure Main;
var p, Grid : OleVariant;
begin
  // Obtain the grid object
  p := Sys.Process('csdemos');
  p.VCLObject('FrmLauncher').VCLObject('BtnViews').ClickButton;
  Grid := p.VCLObject('FrmViewDemo').VCLObject('Panel2').VCLObject('DBGrid1');

  // Click on a column header
  Grid.ClickColumnHeader ('FirstName');
end;

C++Script, C#Script

function Main ()
{
  var p, Grid;

  // Obtain the grid object
  p = Sys["Process"]("csdemos");
  p["VCLObject"]("FrmLauncher")["VCLObject"]("BtnViews")["ClickButton"]();
  Grid = p["VCLObject"]("FrmViewDemo")["VCLObject"]("Panel2")["VCLObject"]("DBGrid1");

  // Click on a column header
  Grid["ClickColumnHeader"]("FirstName");
}

See Also

Working With Borland TDBGrid
ClickColumnHeader Action (Grid Controls)

Highlight search results