none
Detect mouse leaving from a list view item RRS feed

  • Question

  • Hi all,
       I am working on a windows application with a list view on a form.
    Now I wanted to show hand cursor when mouse is over list view item and
    default(arrow) cursor at other places.

      List view's ItemMouseHover event can tell me that mouse is on the
    item and here I can change my cursor to hand. But I have no clue to
    change it back to default cursor when mouse is moved out of the list
    view item.

      How can I detect that mouse is moved away/out of the list view
    item??

      I have also tried to use HitTest method of the list view in the
    MouseMove event but it is causing lots of overhead and sometimes hangs
    the application. So I am not using this option.
      Can someone give me an idea how to achieve it.

    Thanks!!
    Wednesday, October 8, 2008 10:39 AM

Answers

  • Hi,

    I hope this reduces the performance hit, by using the cursor points

    //use cursor points.
    Point p = lstViewTest.PointToClient(new Point (Cursor.Position.X,Cursor.Position.Y));

    //now get the item.
      item = Me.ListView1.GetItemAt(p.X,p.Y )



    Thanks,
    • Proposed as answer by Krishna Nandu Friday, October 10, 2008 8:46 AM
    • Marked as answer by jack 321 Monday, October 13, 2008 2:54 AM
    Friday, October 10, 2008 8:43 AM
  •  Hello Mohit Jain,
        I am not usre if this is what you are looking for, but you could try changing the list view's HoverSelection property to true.

    Hope this helps!
    Thanks!
    chukrum47
    How are a plum and a rabbit similar? They're both purple, except for the rabbit.
    • Marked as answer by jack 321 Monday, October 13, 2008 2:54 AM
    Friday, October 10, 2008 10:40 AM

All replies

  • Hello Mohit Jain,
        Try going to the property sheet of the designer, click on the List, go to the property sheet event page (the lightning bolt at the top), and add an event for MouseLeave. This event should be called whenever the cursor leaves the visible portion of the control. Alternatively, set the ListView cursor property to 'Hand'; this should have the same effect.

    Hope this helps!
    Thanks!
    chukrum47
    How are a plum and a rabbit similar? They're both purple, except for the rabbit.
    Wednesday, October 8, 2008 10:46 AM
  • Hi,
      Thanks for your quick response.
     
      Using MouseLeave handler would not solve the problem as I want leave event for individual list view items not the entire list view.

      I have many items with the gaps between them. Using your solution will show the hand cursor when the mouse is between the two items i.e. between gaps and I don't want to show the hand cursor over the entire list view. I wanted to have it only on the individual list view items and not even between gaps.

    Thanks again!!

    Wednesday, October 8, 2008 10:58 AM
  • Hi,

    In the Listview1_Mousemove, add the code below

    dim item as ListViewItem
    item = Me.ListView1.GetIteamAt(e.X,e.Y)
    If Not item Is Nothing Then
             
    ' code to change the cursor icon       
    Else

    'Code for normal icon



    I think this will work for your requirement





     
    Wednesday, October 8, 2008 11:25 AM
  • Hi,
      Thanks again for response!!

      Using GetItemAt() method is also causing lots of overhead and hanging up the application. CPU utilization clock is showing up 100% usage when mouse is moved over the list view and various items for a considerable amount of time.
     
      Is there some other alternative exist? ?
    Friday, October 10, 2008 7:16 AM
  • Hi,

    I hope this reduces the performance hit, by using the cursor points

    //use cursor points.
    Point p = lstViewTest.PointToClient(new Point (Cursor.Position.X,Cursor.Position.Y));

    //now get the item.
      item = Me.ListView1.GetItemAt(p.X,p.Y )



    Thanks,
    • Proposed as answer by Krishna Nandu Friday, October 10, 2008 8:46 AM
    • Marked as answer by jack 321 Monday, October 13, 2008 2:54 AM
    Friday, October 10, 2008 8:43 AM
  •  Hello Mohit Jain,
        I am not usre if this is what you are looking for, but you could try changing the list view's HoverSelection property to true.

    Hope this helps!
    Thanks!
    chukrum47
    How are a plum and a rabbit similar? They're both purple, except for the rabbit.
    • Marked as answer by jack 321 Monday, October 13, 2008 2:54 AM
    Friday, October 10, 2008 10:40 AM