Solved

VB.net - problem getting the ListIndex of ListView without clicking

Posted on 2008-10-22
2
595 Views
Last Modified: 2012-05-05
Hi
I am trying to get the ListIndex of a ListVew without clicking it but the last two lines of the following code
cause errors.

 Sub Get_Row_Index_on_Mousehover()
        Dim LocalMousePosition As Point
        LocalMousePosition = Me.lsvAction.PointToClient(Cursor.Position)
        Debug.WriteLine("X = " & LocalMousePosition.X & ", " & LocalMousePosition.Y)

        Dim x As Integer = LocalMousePosition.X
        Dim y As Integer = LocalMousePosition.Y
        Dim returnValue As ListViewItem
        returnValue = Me.lsvAction.GetItemAt(x, y)

        MsgBox(returnValue.Index)
 
    End Sub
0
Comment
Question by:murbro
2 Comments
 
LVL 19

Accepted Solution

by:
Stephen Manderson earned 500 total points
ID: 22778626
Hi there

Try the following and have it handle the mouse move event of the listview

Regards
Steve


    Private Sub ListView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseMove
 
        Dim LocalMousePosition As Point
        LocalMousePosition = Me.ListView1.PointToClient(Cursor.Position)
 
        Dim x As Integer = LocalMousePosition.X
        Dim y As Integer = LocalMousePosition.Y
 
        Dim HoveredItem As ListViewItem = Me.ListView1.GetItemAt(x, y)
        If HoveredItem Is Nothing Then Return
 
        MsgBox(HoveredItem.Index)
 
    End Sub

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 31508831
Great answer. Thanks very much
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question