Solved

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

Posted on 2008-10-22
2
592 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now