Skip to main content

TcxCustomListView.GetHitTestInfoAt(Integer,Integer) Method

Determines the elements of the control located under the specified point.

Declaration

function GetHitTestInfoAt(X: Integer; Y: Integer): THitTests;

Parameters

Name Type
X Integer
Y Integer

Returns

Type
THitTests

Remarks

Use the GetHitTestInfoAt method to determine the element of the control located under the specified point. The point is specified by its horizontal and vertical coordinates using the X and Y method parameters. Note that coordinates must be set in the control’s client coordinates. Thus, if you have screen coordinates of the point, use the control’s ScreenToClient method to obtain client coordinates.

The following code handles the TcxListView.OnClick event to change the images, displayed next to the list view items. If a user clicks a list view, then the item’s state image is replaced with a check mark:

procedure TForm1.cxListView1Click(Sender: TObject);
var
  MousePos: TPoint;
  AItem: TListItem;
begin
  MousePos := Mouse.CursorPos;
  MousePos := cxListView1.ScreenToClient(MousePos);
  AItem := cxListView1.GetItemAt(MousePos.X, MousePos.Y);
  if AItem <> nil then
  begin
    if htOnIcon in cxListView1.GetHitTestInfoAt(MousePos.X, MousePos.Y) then
    begin
      if AItem.StateIndex <> 3 then
      AItem.StateIndex := 3
    end;
  end;
end;

The result of the code execution is demonstrated below:

See Also