TcxCustomCheckListBox.ItemAtPos(TPoint,Boolean) Method
Returns the index of the item at the specified coordinates.
Declaration
function ItemAtPos(const APos: TPoint; AExisting: Boolean): Integer;
Parameters
Name | Type |
---|---|
APos | TPoint |
AExisting | Boolean |
Returns
Type |
---|
Integer |
Remarks
This function returns the index of the item at the specified position. The APos parameter specifies the item’s coordinates relative to the top left corner of the control. If the coordinates refer to a point outside the control’s bounds, the function returns -1.
The AExisting parameter determines the value returned when the specified point is within the list box, but does not refer to an existing item. If AExisting is True, the function will return valid indexes only if the point belongs to an existing item. Otherwise, the function returns -1. If AExisting is False and the point does not belong to an existing item, the function will return the index of the last item in the list box plus one.
The following example shows how you can inform the user about the item currently located under the mouse cursor while moving over the list box. A handler for the control’s OnMouseMove event is listed below:
procedure TForm1.cxCheckListBox1MouseMove(Sender: TObject;
Shift: TShiftState; X, Y: Integer);
var
ItemIndex: Integer;
begin
ItemIndex := cxCheckListBox1.ItemAtPos(Point(X, Y), True);
if ItemIndex <> -1 then
StatusBar1.SimpleText := cxCheckListBox1.Items[ItemIndex];
end;