Question GET THE INDEX of the SELECTED SubItem of a Listview

pidyok

Member
Joined
Feb 10, 2009
Messages
19
Programming Experience
Beginner
EXAMPLE: listview of 8 columns and 13 rows... on selection, my mouse is over item row 10 column 6, how will i be able to get the index of that sub item??? so far no sample codes available over the net yet...

< lsv1.SelectedItems.Item(0).Index > only works showing index of the main item in a row... i.e. will display row 10, col 0 index only even if my mouse is over item row 10 column 6 upon selection...

any suggestions???

thanks!
 
Private Sub lvList_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lvList.MouseUp
Dim x As Integer, i As Integer, lvItem As ListViewItem, iSubItemIndex As Integer

lvItem= lvList.GetItemAt(e.X, e.Y)
If Not lvItem Is Nothing Then
x = 0
For i = 0 To lvList.Columns.Count - 1
If x + lvList.Columns(i).Width > e.X Then
iSubItemIndex = i
Exit For
End If
x = x + lvList.Columns(i).Width
Next i
End If

'At this point:
'lvItem is the ListViewItem clicked on
'iSubItemIndex is the SubItems index

'IMPORTANT this only works if the ListView has not been horizontally scrolled.
'I have not figured out how to detect how to cope with horizontally scrolling yet.
End Sub

Hope this helps

TrevC
 
Back
Top