VB.net get row index of DataGridView without clicking


I need to find the row index of a DataGridView without clicking in a Drag and Drop.
I used the code below for a ListView.
How do I do this for a DataGridView.
Private Sub GetListIndexWithoutClicking()
        Dim LocalMousePosition As Point
        LocalMousePosition = Me.lsvAction.PointToClient(Cursor.Position)

        Dim x As Integer = LocalMousePosition.X
        Dim y As Integer = LocalMousePosition.Y

        Dim HoveredItem As ListViewItem = Me.lsvAction.GetItemAt(x, y)
        If HoveredItem Is Nothing Then
            ListIndex_on_Mousehover = -1
        End If

        ListIndex_on_Mousehover = HoveredItem.Index

    End Sub

Open in new window

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
Shahan AyyubSenior Software Engineer - iOSCommented:
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
thanks very much
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.