Solved

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

Posted on 2008-10-22
2
599 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Murray Brown
ID: 31508831
Great answer. Thanks very much
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

617 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