ListBox.IndexFromPoint()

RobEmDee

Centurion
Joined
Mar 25, 2003
Messages
130
Location
Richmond, VA
I am using the IndexFromPoint() method of the ListBox inside of the MouseMove event handler to identify which ListBox item a user's mouse is hovering over at any given point. This has worked well. The one annoyance I have found is that when the mouse is over empty ListBox space below the last ListBox item, IndexFromPoint() returns the index of the last ListBox item even though technically the mouse is not over any items. Does anyone have a quick workaround for this? Thanks.
 
RobEmDee said:
The one annoyance I have found is that when the mouse is over empty ListBox space below the last ListBox item, IndexFromPoint() returns the index of the last ListBox item even though technically the mouse is not over any items.
:confused: Sure? I tied it out and when the cursor enters the space below the last item IndexFromPoint() returns -1 (even when the mouse enters the listbox on white space)! The only problem you might experience is, when the last item is right above the lower border of the box or if the mouse leaves the listbox on the left, right or top. Then the event is not triggered and if you store the index in a variable, it holds the index of the last item you hovered over. This could easily be solved with the MouseLeave event.
 
APaule: Thanks for taking a look.

I realize now that I am only experiencing the behavior I described with ListBoxes that I have taken ownership of the drawing (DrawMode = OwnerDrawVariable).
 
Back
Top