Solved

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

11 Experts available now in Live!

Get 1:1 Help Now