Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-10-22
2
Medium Priority
?
601 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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

660 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