1. Home
  2. Computing & Technology
  3. Delphi Programming

Select ListBox items as mouse hovers over them

By Zarko Gajic, About.com

Here's how to set the selected item in a ListBox as mouse moves over the list box.

Just assign the next code to the OnMouseMove event handler for the ListBox (ListBox1) component.

~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.ListBox1MouseMove
   (Sender: TObject; Shift: TShiftState; X, Y: Integer) ;
begin
   ListBox1.ItemIndex := ListBox1.ItemAtPos(Point(x,y), True) ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» What's the word under the mouse cursor in a TRichEdit?
« Enable or disable a control by name

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TMouse
  6. Select ListBox items as mouse hovers over them

©2009 About.com, a part of The New York Times Company.

All rights reserved.