Results 1 to 3 of 3

Thread: how can i get the index of specific item in my listview

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2008
    Posts
    52

    how can i get the index of specific item in my listview

    is it possible to get the index of specific item in my listview?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how can i 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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: how can i get the index of specific item in my listview

    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:
    1. Private Sub Form_Load()
    2.     With ListView1
    3.         .ListItems.Add Key:="k1", Text:="huxley"
    4.         .ListItems.Add Key:="k2", Text:="koolsid"
    5.         .ListItems.Add Key:="k3", Text:="LaVolpe"
    6.     End With
    7. End Sub
    8.  
    9. Private Sub CommandButton1_Click()
    10.     Dim itm As ListItem, SearchStrg As String
    11.    
    12.     '~~> String, the index of which you want to find
    13.     SearchStrg = "koolsid"
    14.    
    15.     With ListView1
    16.         Set itm = .FindItem(SearchStrg, lvwText, , lvwPartial)
    17.             If Not itm Is Nothing Then
    18.                 '~~> Display the index
    19.                 MsgBox itm.Index
    20.             End If
    21.     End With
    22.     Set itm = Nothing
    23. End Sub

    Hope this helps...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width