Index of row in a listview

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

In Mouce_Hover event of a listview control, I need to get the rownumber
without selecting the item. For example if I move mouce over row 6 I need to
get value of six and so on. How this is possible?
Thanks in advance,

Roy
 
Hi,

I would place the index number in the list view items tag. In the
hover event I would use the listviews GetItemAt function to get the item the
mouse is over.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
For x As Int16 = 0 To 50
Dim lvi As New ListViewItem("Item " & x.ToString)
lvi.Tag = x
ListView1.Items.Add(lvi)
Next
End Sub

Private Sub ListView1_MouseHover(ByVal sender As Object, ByVal e As
System.EventArgs) Handles ListView1.MouseHover
Dim pt As Point
pt = ListView1.PointToClient(Me.MousePosition)

Try
Dim lvi As ListViewItem = ListView1.GetItemAt(pt.X, pt.Y)
Me.Text = lvi.Tag.ToString
Catch ex As Exception
Trace.WriteLine(ex.ToString)
End Try
End Sub

Ken
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top