is it possible to get the index of specific item in my listview?
Printable View
is it possible to get the index of specific item in my listview?
ListView1.ListItems(x).Index
But if you know x then you know the index, correct?
If you want to know the index of the currently selected item, testing first to see if anything is actually selected:
If Not ListView1.SelectedItem Is Nothing Then Index = ListView1.SelectedItem.Index
If the item is not selected and you know the text then you can do this to get the index. For example. If the listview has 3 items as show below and I am want to know the index of "koolsid" then I can use the code below....
vb Code:
Private Sub Form_Load() With ListView1 .ListItems.Add Key:="k1", Text:="huxley" .ListItems.Add Key:="k2", Text:="koolsid" .ListItems.Add Key:="k3", Text:="LaVolpe" End With End Sub Private Sub CommandButton1_Click() Dim itm As ListItem, SearchStrg As String '~~> String, the index of which you want to find SearchStrg = "koolsid" With ListView1 Set itm = .FindItem(SearchStrg, lvwText, , lvwPartial) If Not itm Is Nothing Then '~~> Display the index MsgBox itm.Index End If End With Set itm = Nothing End Sub
Hope this helps...