Skip to content

TAutomationStringGrid

Mark Humphreys edited this page May 18, 2021 · 4 revisions

Using an extended TStringGrid control that implements UIAutomation patterns, it is possible to add limited interaction with TStringGrid.

The TAutomatedStringGrid allows the automation of some of the elements of the TStringGrid. It extends the control to allow it to interact with the MS-UIAutomation libraries.

TAutomatedStringGridItem

Represents an item associated with a TStringGrid 'cell'.

As the automation does not expose the cells fully (as they do not technically exist in the TStringGrid), it is necessary to do the following ..

  // Get the grid item
  item := grid.GetItem(3,3);

  // Select it
  item.Select;
  
  // Create a mouse to move the pointer
  mouse := TAutomationMouse.Create;
  
  // Get the bounding rectangle of the item (this is relative to the grid)
  itemRect := item.BoundingRectangle;
  
  // Get the overall grid bounding rectangle
  gridRect := grid.BoundingRectangele;
  
  // Move to the correct location, offsetting to make sure the mouse point is inside the cells itself
  mouse.Location := TPoint.Create(gridRect.left + itemRect.left +15, gridRect.Top + itemRect.top +15);
  mouse.LeftClick;
  mouse.RightClick;