Home > Software engineering >  How to detect the row of a ControlList at mouse position
How to detect the row of a ControlList at mouse position

Time:12-05

I want change the hint of the ControlList, detecting which row the mouse is over, so for example the hint could say 'Row 6'

I know that I can do this with TStringList as shown in the following example.

TStringList Example:

procedure TForm1.StringGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
  Col, Row: Integer;
begin
  StringGrid1.MouseToCell(X, Y, Col, Row);
  StringGrid1.Hint := IntToStr(Col)   '   '   IntToStr(Row);
end; 

ControlList Example:

procedure TForm1.ControlList1MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
    var
   Row: Integer;
    begin
       ControlList1.  <--------Looking for something like Mouse to Row
       ControlList1.Hint := IntToStr(Row);
    end;

FYI, in the ControlList BeforeDraw Item AIndex is available. It would be great to get the the AIndex or Row.

ControlList1BeforeDrawItem(
  AIndex: Integer; ACanvas: TCanvas; ARect: TRect; AState: TOwnerDrawState);

CodePudding user response:

TControlList exposes a property HotItemIndex for that.

  • Related